几个月前我写了一篇关于它的帖子。
我还写了关于如何从类中添加属性的文章,例如不使用 id(我不喜欢它)而是使用令牌。
Read the post here...
基础知识:
获取带有 id 的路径
has_attached_file :avatar,
:styles =>
{
:tiny => "48x48>",
:preview => "175x175>",
:large => "300x300>",
:huge => "500x500>"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":class/:attachment/:id/:style.:extension",
:bucket => 'lopsum',
:default_url => "/images/photo01.jpg"
而且,如果您想将其更改为其他内容...
has_attached_file :avatar,
:styles =>
{
:tiny => "48x48>",
:preview => "175x175>",
:large => "300x300>",
:huge => "500x500>"
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":class/:attachment/:token/:style.:extension",
:bucket => 'lopsum',
:default_url => "/images/photo01.jpg"
在初始化器中
Paperclip.interpolates :token do |attachment, style|
attachment.instance.token
end