我寫了一篇關於它在幾個月前。 我也寫過關於如何從類中添加屬性,例如不使用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