我在项目中使用了paperclip。
有关模型看起来像这样:
class Asset < ActiveRecord::Base
has_paper_trail # Track model with paper_trail
has_attached_file :image, :styles => { :medium => "300x300>"},
:path => ":rails_root/public/attachments/project_#{:project_id}/ressources/:basename_:style.:extension"
belongs_to :project
end
如您所见,我希望在我的图片路径中拥有相关项目的ID,我该如何制作?
答案 0 :(得分:6)
试试这个
has_attached_file :image, :styles => { :medium => "300x300>"},
path => ":rails_root/public/attachments/:project_id/ressources/:basename_:style.:extension"
然后写
Paperclip.interpolates :project_id do |attachment, style|
"project_#{attachment.instance.project_id}"
end