RAILS:回形针和基于创建日期的目录结构

发布于 2024-09-29 11:44:36 字数 689 浏览 3 评论 0原文

有谁知道我如何配置我的rails模型,该模型使用回形针进行数据存储,以使用基于创建日期的目录,例如在fleximage中?

目前我正在使用:

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

但我需要的是这样一个

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"

简单的:目录路径中的created_at也会

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

提前帮助Thanx,

Alex

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 path would also help

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

Thanx in advance,

Alex

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情痴 2024-10-06 11:44:36

您可以将自己的插值添加到回形针。举一个简单的例子:

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

现在您可以在 :path 选项中使用 :year,如下所示:

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

您可以定义三个插值::year:month:day,或者仅返回整个年/月/日字符串。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文