i keep getting an ActiveRecord::UnknownAttributeError:
unknown attribute: image开发者_C百科able_id
the code:
polymorphic image model:
class Image < ActiveRecord::Base
mount_uploader :asset, ImageUploader
belongs_to :imageable, :polymorphic => true
end
the model that is attempting a polymorphic association for 2 different image types:
has_one :image, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :image
has_one :thumbnail, :as => :imageable, :dependent => :destroy
accepts_nested_attributes_for :thumbnail
the controller action that attempts to build the images (the first "build_image" actually fires, the error references "build_thumbnail":
def new
@item = @item_class.new #item is instantiated elsewhere
@item.build_image #this works
@item.build_thumbnail #this throws my error "unknown attribute: imageable_id"
end
thanks!
EDIT FIXED
You just need to add a :class_name => Image option to the has_one :thumbnail relationship. (thx for checking me @Tilo)
精彩评论