2010-10-27 39 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