简体   繁体   English

回形针,在rails根文件夹之外设置路径

[英]Paperclip, set path outside of rails root folder

I have two separate rails apps, say MyApp and MyAppAdmin. 我有两个单独的Rails应用程序,例如MyApp和MyAppAdmin。 In MyAppAdmin there is ability to attach images with paperclip gem, this images should be available on the first app (MyApp). 在MyAppAdmin中,可以使用回形针gem附加图像,该图像应在第一个应用程序(MyApp)上可用。 Fe I may add a user avatar in MyAppAdmin, and it should be displayed in MyApp. 例如,我可以在MyAppAdmin中添加用户头像,并且该头像应显示在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. 在我的config.yml中,但是没有用。 It just adds to the default paperclip path (same with relative path like "../temp/shared"). 它只是添加到默认的回形针路径(与相对路径(如“ ../temp/shared”相同))。 https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L23 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. 到我的development.rb文件,没有运气。

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 * MyApp使用Rails 3.2,MyAppAdmin-rails 2.3.18

The options ":path" and ":url" must be used together in your case. 在您的情况下,必须一起使用选项“:path”和“:url”。 I believe what is missing is some configurations on your webserver and the :url configuration. 我相信您的网络服务器上缺少一些配置以及:url配置。

":path" --> tells paperclip where the files are inside the server file system. “:path”->告诉回形针文件在服务器文件系统内的位置。
":url" --> tells paperclip how to determine the url to be generated. “:url”->告诉回形针如何确定要生成的url。 It is relative to the website URL. 它相对于网站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. 因此,通过WebServer上的配置,您应该将服务器文件夹“:path”映射到rails app文件夹结构下的虚拟目录。

This virtual directory should than reflect the configuration in the ":url" option. 然后,该虚拟目录应在“:url”选项中反映配置。

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: 第一步,在Rails应用程序下使用以下名称配置一个虚拟文件夹:

MyNewVirtualFolder

and point it to "/tmp/shared" 并将其指向“ / tmp / shared”

Step two configure 第二步配置

:url => "/MyNewVirtualFolder/:class/:id_partition/:style.:extension"

and finally re-start your rails app. 最后重新启动您的Rails应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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