2013-02-14 2 views
0

두 모델 PersonBrain이 있습니다. Personhas_one:brainBrainbelongs_to이다./person/update를 통해 Brain 속성을 지정하고 싶습니다. 레일 콘솔에서이 모델이 액세스 할 수있는 특성을 표시하지 않는 이유는 무엇입니까?

class Person < ActiveRecord::Base 
    has_one :brain 
    attr_accessible :name 
    attr_accessible :brain 
    accepts_nested_attributes_for :brain 

end 

class Brain < ActiveRecord::Base 
    belongs_to :person 
    attr_accessible :weight_kg 

    attr_accessible :person 
    accepts_nested_attributes_for :person 
end 

내가 Person.brain에 할당 할 수 있습니다

> p = Person.first 
=> #<Person id: 1, name: "Dave", created_at: "2013-02-14 20:17:35", updated_at: "2013-02-14 20:17:35"> 

> p.brain.weight_kg = 5.0 
    Brain Load (0.2ms) SELECT "brains".* FROM "brains" WHERE "brains"."person_id" = 1 LIMIT 1 
=> 5.0 
> p.save 
    (0.6ms) begin transaction 
    (0.6ms) UPDATE "brains" SET "weight_kg" = 5.0, "updated_at" = '2013-02-14 20:18:11.010544' WHERE "brains"."id" = 1 
    (317.6ms) commit transaction 
=> true 

을 웹 양식을 통해 (그리고 콘솔을 통해) 내가 할 수없는 때문에 잘 착용 오류 "수 없습니다 보호 속성을 대량 할당 : brain_attributes ".

attr_accessible :weight_kgBrain이고, Person에는 accepts_nested_attributes_for :brain이 있습니다. 잘못 입력했기 때문입니다.

무엇이 누락 되었습니까?

+0

감사 신성. 이 설정에서 다른 문제가 있음이 드러났지만 조언을 받았다. –

답변

2

변경 attr_accessible에 :

attr_accessible :brain_attributes 
관련 문제