我有这个(这些)型号
Portfolio
-- PortfolioItem item
-- Image image
has_attachment :attachment所有的都有很好的插件,我想要的url :附件来反映这个组织,例如一个实例
photos/holiday_in_venice/ponte_vecchio (all slugs of the respective hierarchy)将生成此url。
photos(??)/holiday_in_venice(??)/:slug/:style.:extension如何在创建回形针路径/url期间访问这些前置器对象?
目前我只能这样做
ponte_vecchio/small.png发布于 2012-07-27 14:48:53
您需要创建custom interpolations。之后,您就可以定义:url和:path了。
在config/initializers/文件夹中放置一个名为paperclip.rb的文件,并执行以下操作:
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"https://stackoverflow.com/questions/11681787
复制相似问题