Paperclip,在 rails 根文件夹之外设置路径 [英] Paperclip, set path outside of rails root folder

查看:37
本文介绍了Paperclip,在 rails 根文件夹之外设置路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的 rails 应用程序,比如 MyApp 和 MyAppAdmin.在 MyAppAdmin 中,可以使用回形针宝石附加图像,该图像应该在第一个应用程序 (MyApp) 上可用.F.e.我可以在MyAppAdmin中添加一个用户头像,它应该显示在MyApp中.

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?

我尝试使用类似
路径:/tmp/shared"
在我的 config.yml 中,但它不起作用.它只是添加到默认的回形针路径(与../temp/shared"等相对路径相同).https://github.com/thoughtbot/paperclip/blob/master/lib/paperclip/attachment.rb#L23

我也尝试添加类似
Paperclip::Attachment.default_options[:path] = '/tmp/shared/:class/:id_partition/:style.:extension'
到我的 development.rb 文件,运气不好.

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.

是否可以在实际 rails 应用程序文件夹之外设置回形针中图像的路径?

Is it possible to set path for images in paperclip OUTSIDE the actual rails app folder?

*MyApp 使用 rails 3.2,MyAppAdmin - rails 2.3.18

*MyApp uses rails 3.2, MyAppAdmin - rails 2.3.18

推荐答案

在您的情况下,必须同时使用选项 ":path" 和 ":url".我相信缺少的是您的网络服务器上的一些配置和 :url 配置.

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" --> 告诉回形针文件在服务器文件系统中的位置.
":url" --> 告诉回形针如何确定要生成的 url.它相对于网站 URL.

":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.

因此,通过 WebServer 上的配置,您应该将:path"所在的服务器文件夹映射到 rails 应用程序文件夹结构下的虚拟目录.

So through configurations on your WebServer you should map the server folder where ":path" to a virtual directory under the rails app folder structure.

这个虚拟目录应该反映:url"选项中的配置.

This virtual directory should than reflect the configuration in the ":url" option.

例如让我们说你做了

:path => "/tmp/shared/:class/:id_partition/:style.:extension"

第一步在您的 rails 应用程序下配置一个虚拟文件夹,名称为:

Step one configure a virtual folder under your rails app with the name:

MyNewVirtualFolder

并将其指向/tmp/shared"

and point it to "/tmp/shared"

第二步配置

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

最后重新启动您的 rails 应用程序.

and finally re-start your rails app.

这篇关于Paperclip,在 rails 根文件夹之外设置路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆