2010-10-27 37 views
2

沒有人知道我可以如何配置我的rails模型,它使用數據存儲回形針來使用基於創建日期的目錄,例如在fleximage中?RAILS:基於回形針和創建日期的目錄結構

目前我使用的是:

has_attached_file :bookblock, :path => "#{CONF['storage_path']}bookblock/:id_partition/:style.:content_type_ehas_attached_filextension" 

,但我需要的是這樣的事情

​​

簡單:created_at目錄路徑,也將有助於

{CONF['storage_path']}/:created_at/bookblock/:id_partition/:style.:content_type_ehas_attached_filextension" 

Thanx提前,

亞歷克斯

回答

4

您可以添加自己的插值到Paperclip。舉個簡單的例子:

has_attached_file :bookblock, :path => "#{CONF['storage_path']}bookblock/:year/:id/:style.:content_type_ehas_attached_filextension" 

你可以定義三個插值::year:month:day,或只是一個返回

Paperclip.interpolates :year do |attachment, style| 
    attachment.instance.created_at.year 
end 

現在你可以在:path選項像這樣使用:year全年/月/日的字符串。

+0

thanx很多;)現在我知道名稱「插值」,我可以找到一切:https://github.com/thoughtbot/paperclip/wiki/Interpolations – 2010-12-13 15:47:44