嗨我有使用has_one关联使用select_box的问题。 我的模型image_element是多态的:
class ImageElement < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
belongs_to :image
end
模特图片:
class Image < ActiveRecord::Base
attr_accessible :image, :application_id
belongs_to :application
has_many :image_elements, as: :imageable
mount_uploader :image, ImagesUploader
end
和具有以下关联的模型级别:
has_one :image_element, as: :imageable
has_one :image, through: :image_element
accepts_nested_attributes_for :image_element
在级别表单中,我正在尝试创建select_box以选择level_element作为级别。
= f.select(:image_element, ImageElement.all.collect{|i| i.image.image.thumb})
选择框正在查看,但是当我提交表单时,我从服务器获得以下输出:
WARNING: Can't mass-assign protected attributes: image_element
提前感谢:)
答案 0 :(得分:1)
尝试将image_element_attributes
添加到attr_accessible
attr_accessible :image, :application_id, :image_element_attributes