RAILS: paperclip and creation date based directory structure
does anyone know how I can configure my rails model, which is using paperclip for data storage, to use creation date based directories like for example in fleximage ??
At present I'm using:
has_attached_file :bookblock, :path => "#{CONF['storage_path']}bookblock/:id_partition/:style.:content_type_ehas_attached_filextension"
but what I need is something like this
has_attached_file :bookblock, :path => "# {CONF['storage_path']}bookblock/:created_at_year/:created_at_month/:created_at_day/:c:id_partition/:style.:content_type_ehas_attached_filextension"
a simple :created_at in the directory p开发者_JAVA技巧ath would also help
{CONF['storage_path']}/:created_at/bookblock/:id_partition/:style.:content_type_ehas_attached_filextension"
Thanx in advance,
Alex
You can add your own interpolations to Paperclip. To give a simple example:
Paperclip.interpolates :year do |attachment, style|
attachment.instance.created_at.year
end
Now you can use :year
in the :path
option like this:
has_attached_file :bookblock, :path => "#{CONF['storage_path']}bookblock/:year/:id/:style.:content_type_ehas_attached_filextension"
You could define three interpolations: :year
, :month
and :day
, or just one that returns the whole year/month/day string.
精彩评论