Rails 和 Paperclip 在特定路径中存储图像设置错误 URL
Rails and Paperclip storing images in a specific path sets wrong URL
我想使用普通文件存储适配器存储我的图像。
这是我的 PAPERCLIP_STORAGE_OPTS:
PAPERCLIP_STORAGE_OPTS = {
:styles => { :thumb => '170x170!#', :medium => '450x300!>', :large => '600x400!>',:desktop => '750x300!>'},
:convert_options => { :all => '-quality 100' },
:processor => [ :papercrop ],
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename"
}
这是我的模型:
class User < ActiveRecord::Base
attr_accessor :PAPERCLIP_STORAGE_OPTS
has_attached_file :user_photo, PAPERCLIP_STORAGE_OPTS_THUMB
当用户上传照片时 - 它实际上会将图像存储在我系统上的正确位置:
/opt/www/myapp/images/users/user_photos/000/000/050/original/picture
但是当我去显示图像时,像这样:
<%=image_tag current_user.user_photo.url(:thumb), :height=> "30", :width=> "30" %>
找不到图像,在我的日志中我看到图像请求位于 URL:
ActionController::RoutingError (No route matches [GET] "/system/users/user_photos/000/000/050/thumb/picture"):
创建的完整 URL 是:
https://www.myapp.com/system/users/user_photos/000/000/050/thumb/picture?1460285803 - 无法解决。
如何配置 paperclip 以允许我的图像存储在这个特定的 url /opt/www/myapp/images/ 中,并且仍然可以通过我的 rails 应用程序中的 Paperclip 正确访问和链接?
您必须设置 URL 选项:
对我来说是:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>", :small=>"60x60>" },
:path => ':rails_root/public/system/:class/:id/:style/:filename',
:url => '/system/:class/:id/:style/:filename'
不确定你的情况,因为你直接将图像存储在应用程序文件夹中,所以你可以尝试(从控制台测试并修改它):
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename",
:url => '/images/:class/:attachment/:id_partition/:style/:filename'
我想使用普通文件存储适配器存储我的图像。
这是我的 PAPERCLIP_STORAGE_OPTS:
PAPERCLIP_STORAGE_OPTS = {
:styles => { :thumb => '170x170!#', :medium => '450x300!>', :large => '600x400!>',:desktop => '750x300!>'},
:convert_options => { :all => '-quality 100' },
:processor => [ :papercrop ],
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename"
}
这是我的模型:
class User < ActiveRecord::Base
attr_accessor :PAPERCLIP_STORAGE_OPTS
has_attached_file :user_photo, PAPERCLIP_STORAGE_OPTS_THUMB
当用户上传照片时 - 它实际上会将图像存储在我系统上的正确位置:
/opt/www/myapp/images/users/user_photos/000/000/050/original/picture
但是当我去显示图像时,像这样:
<%=image_tag current_user.user_photo.url(:thumb), :height=> "30", :width=> "30" %>
找不到图像,在我的日志中我看到图像请求位于 URL:
ActionController::RoutingError (No route matches [GET] "/system/users/user_photos/000/000/050/thumb/picture"):
创建的完整 URL 是:
https://www.myapp.com/system/users/user_photos/000/000/050/thumb/picture?1460285803 - 无法解决。
如何配置 paperclip 以允许我的图像存储在这个特定的 url /opt/www/myapp/images/ 中,并且仍然可以通过我的 rails 应用程序中的 Paperclip 正确访问和链接?
您必须设置 URL 选项:
对我来说是:
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>", :small=>"60x60>" },
:path => ':rails_root/public/system/:class/:id/:style/:filename',
:url => '/system/:class/:id/:style/:filename'
不确定你的情况,因为你直接将图像存储在应用程序文件夹中,所以你可以尝试(从控制台测试并修改它):
:path => "/opt/www/myapp/images/:class/:attachment/:id_partition/:style/:filename",
:url => '/images/:class/:attachment/:id_partition/:style/:filename'