您需要创建
custom interpolations
。之后,您可以定义
:url
和
:path
。
放入一个名为
paperclip.rb
在您的
config/initializers/
文件夹,然后执行以下操作:
Paperclip.interpolates :portfolio_slug do |attachment, style|
attachment.instance.portfolio_item.portfolio.title.parameterize
end
Paperclip.interpolates :portfolio_slug do |attachment, style|
attachment.instance.portfolio_item.title.parameterize
end
之后,您可以像这样使用这些插值:
has_attached_file :attachment,
:path=>":rails_root/public/photos/:portfolio_slug/:item_slug/:style.:extension",
:url=>"/photos/:portfolio_slug/:item_slug/:style.:extension"