【发布时间】:2011-10-16 12:25:14
【问题描述】:
我正在尝试配置 Paperclip 以根据实例的类别属性提供不同的缺失图像。每个类别的对象都有自己的缺失图像。
这是我的第一次拍摄:
编辑以添加完整模型:
class Service < ActiveRecord::Base
attr_accessible :logo, :logo_file_name, :logo_content_type, :logo_file_size, :logo_updated_at
belongs_to :category, :counter_cache => true
has_attached_file :logo,
:path => "/:id-:style-:filename",
:url => ":s3_eu_url",
:default_url => "/logos/:style/#{self.category.name]}.png",
:styles => { :large => "600x400>",
:medium => "300x200>",
:small => "100x75>",
:thumb => "60x42>" }
end
class Category < ActiveRecord::Base
attr_accessible nil
has_many :services
end
在我看来,image_tag service.logo.url(:thumb) 输出:
undefined method `category' for #<Class:0x0000010a731620>
有什么想法吗?
EDIT2:
一个有效的 default_url 是 :default_url => "/logos/:style/missing.png",
解决方案:
在下面查看我自己的答案。
【问题讨论】: