0

您好我有has_one关联工作select_box的问题。 我有模型image_element这是多态:has_one多态关联select_box

class ImageElement < ActiveRecord::Base 
    belongs_to :imageable, polymorphic: true 
    belongs_to :image 
end 

模型图像:

has_one :image_element, as: :imageable 
    has_one :image, through: :image_element 
accepts_nested_attributes_for :image_element 

在关卡的形式我想:这已经得到了以下的关联

​​3210

和模型级创建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 

感谢的提前:)

回答

1

尝试增加image_element_attributesattr_accessible

attr_accessible :image, :application_id, :image_element_attributes 
+0

感谢您的回复,但此解决方案不起作用。我仍然有同样的错误... –

+0

我试图用fields_for来构建它:= f.fields_for:image_element do | p | = p.select(:image,ImageElement.all.collect {| i | i.image.image.thumb})并添加到级别attr_accessible:image_element_attributes,但现在我有以下错误:图像(#80747460)预期,得到字符串(#3361840) –