简体   繁体   中英

Paperclip, set path outside of rails root folder

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). Fe 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM