问题
I have two separate rails apps, say MyApp and MyAppAdmin. In MyAppAdmin there is ability to attach images with paperclip gem, this images should be available on the first app (MyApp). F.e. I may add a user avatar in MyAppAdmin, and it should be displayed in MyApp.
How can I set path for the images that would point to common 'shared' folder, which these two apps can use?
I tried to use something like path: "/tmp/shared"
in my config.yml, but it didn't work. It just adds to the default paperclip path (same with relative path like "../temp/shared"). https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L23
I also tried to to add something like Paperclip::Attachment.default_options[:path] = '/tmp/shared/:class/:id_partition/:style.:extension'
to my development.rb file with no luck.
Is it possible to set path for images in paperclip OUTSIDE the actual rails app folder?
*MyApp uses rails 3.2, MyAppAdmin - rails 2.3.18
回答1:
The options ":path" and ":url" must be used together in your case. I believe what is missing is some configurations on your webserver and the :url configuration.
":path" --> tells paperclip where the files are inside the server file system.
":url" --> tells paperclip how to determine the url to be generated. It is relative to the website URL.
So through configurations on your WebServer you should map the server folder where ":path" to a virtual directory under the rails app folder structure.
This virtual directory should than reflect the configuration in the ":url" option.
for example lets say you did
:path => "/tmp/shared/:class/:id_partition/:style.:extension"
Step one configure a virtual folder under your rails app with the name:
MyNewVirtualFolder
and point it to "/tmp/shared"
Step two configure
:url => "/MyNewVirtualFolder/:class/:id_partition/:style.:extension"
and finally re-start your rails app.
来源:https://stackoverflow.com/questions/29072076/paperclip-set-path-outside-of-rails-root-folder