0

我正在使用 gem PaperClip 将图像上传到我的服务器,但是图像存储在公共/系统中我需要将此 ubication 更改为 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']
4

1 回答 1

3

如果您查看PaperClip 文档,其中说明:

默认情况下,分配为附件的文件放置在:path选项指定的目录中has_attached_file。默认情况下,此位置是 :rails_root/public/system/:class/:attachment/:id_partition/:style/:filename

因此,您需要指定所需路径的:path变量。has_attached_file

希望能帮助到你!

于 2014-12-15T05:46:51.353 回答