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 

: 다음 연관을 가지고있다

class Image < ActiveRecord::Base 
    attr_accessible :image, :application_id 
    belongs_to :application 
    has_many :image_elements, as: :imageable 

    mount_uploader :image, ImagesUploader 
end 

및 모델 수준 레벨에 대한 image_element를 선택하는 select_box를 만들 수 있습니다.

= 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 이제 다음 오류가 있습니다 : Image (# 80747460) expected, String (# 3361840) –