嗨,我在使用 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 来为关卡选择一个 image_element。
= f.select(:image_element, ImageElement.all.collect{|i| i.image.image.thumb})
选择框正在正确查看,但是当我提交表单时,我从服务器得到以下输出:
WARNING: Can't mass-assign protected attributes: image_element
提前致谢 :)