class Photo < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true, :counter_cache => true
has_attached_file :data,
:styles => {
:ppc_full => "500x375>",
:ppc_preview => "250x250",
:ppc_thumb => "76x76#",
:default_url => "shop/:style.jpg"
}
end
class Shop < ActiveRecord::Base
has_many :photos, :as => :attachable, :dependent => :destroy
end
当我这样做时,我希望在没有关联照片时返回默认照片:
image_tag(@shop.photos.last.data.url(:ppc_preview))
但它给了我这个错误:
undefined method `data' for nil:NilClass
我有其他人工作正常,但不是这个。