has_one多态关联select_box

时间:2014-01-20 08:43:29

标签: ruby-on-rails ruby-on-rails-3.2 carrierwave has-one has-one-through

嗨我有使用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

提前感谢:)

1 个答案:

答案 0 :(得分:1)

尝试将image_element_attributes添加到attr_accessible

attr_accessible :image, :application_id, :image_element_attributes