嗨,我正在使用回形针进行图像上传,问题是我想访问部署在同一服务器中的两个应用程序的图像,因为我必须将图像保存在 rails 根目录之外的公共文件夹中。我怎样才能做到这一点?
帮我解决这个问题。
嗨,我正在使用回形针进行图像上传,问题是我想访问部署在同一服务器中的两个应用程序的图像,因为我必须将图像保存在 rails 根目录之外的公共文件夹中。我怎样才能做到这一点?
帮我解决这个问题。
https://github.com/thoughtbot/paperclip在这下到了了解存储。您可以指定所需的任何文件夹的路径。
您可以通过两种方式更改它:
1) config/application.rb 或任何 config/environments/*.rb 文件
module YourApp
class Application < Rails::Application
# Other code...
config.paperclip_defaults = {:storage => :fog, :fog_credentials => {:provider => "Local", :local_root => "#{Rails.root}/public"}, :fog_directory => "", :fog_host => "localhost"}
end
end
2) Rails 初始化程序:
Paperclip::Attachment.default_options[:storage] = :fog
Paperclip::Attachment.default_options[:fog_credentials] = {:provider => "Local", :local_root => "#{Rails.root}/public"}
Paperclip::Attachment.default_options[:fog_directory] = ""
Paperclip::Attachment.default_options[:fog_host] = "http://localhost:3000"