我正在使用gem PaperClip将图像上传到我的服务器,但图像存储在公共/系统中 我需要将此更改为app / assets / images
class User < ActiveRecord::Base
attr_accessible :email, :name,:photo
validates :name, :presence => true
validates :email, :presence => true
has_attached_file :photo, :styles =>
{ :medium => "300x300>", :thumb => "100x100>" }
end
我找到了RailsCasts的这个教程,其中声明了这些选项
has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
答案 0 :(得分:3)
如果你看一下PaperClip documentation那就说明了:
默认情况下,分配为附件的文件位于 由
:path
has_attached_file
选项指定的目录。通过 默认,这个位置是:rails_root/public/system/:class/:attachment/:id_partition/:style/:filename
因此,您需要将:path
has_attached_file
变量指定为所需路径。
希望它有所帮助!