2012-01-25 5 views
0

나는 다음과 같은 모델이 다음 EventParticipantsController 컨트롤러에이 같은 요청에서 HappyHour 모델을로드 지금대량 할당

create_table "event_participants", :force => true do |t| 
    t.string "name" 
    t.string "email" 
    t.boolean "is_organizer" 
    t.boolean "is_attending" 
    t.integer "event_id" 
    t.integer "user_id" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 

    create_table "events", :force => true do |t| 
    t.string "name" 
    t.boolean "is_finalized" 
    t.string "type" 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    end 
add_foreign_key "event_participants", "events", :name => "event_participants_events_fk" 

:

class EventParticipant < ActiveRecord::Base 
belongs_to :event 
has_one :user 

attr_accessible :name, :email, :is_organizer, :is_attending 
end 

class Event < ActiveRecord::Base 
has_many :event_participants 

attr_accessible :event_participants_attributes 

accepts_nested_attributes_for :event_participants 
end 

class HappyHour < Event 
end 

그리고 해당 스키마를 :

@happy_hour = HappyHour.new(params[:happy_hour]) 

하지만 어떤 이유로 인해 HappyHour의 event_parti cipants 특성은 실패가

가 EventParticipantsController 번호로 2012-01-25 18시 55분 31초 -0300 처리에 대해 127.0.0.1 "/ event_participants"POST 시작하는 JS 파라미터로 생성 { "happy_hour을"=> { "event_participants"=> { "0"=> { "name"=> "Diego", "email"=> "[email protected]", "is_organizer"=> "true"}, "1"=> { "name"=> "Test", "email"=> "test_email.com", "is_organizer"=> "false"}}}, "add_event_participant"=> "[email protected]"} 경고 : 보호 된 속성을 대량 지정할 수 없습니다. event_participants

무엇이 누락 되었습니까? 나는 일대일 관계에서 관련 객체에 대한 대량 대입에 대한 많은 예제를 발견했지만 일대 다 대다수는 내 사례와 다릅니다.

답변

1

event_participants 대신 event_participants_attributes을 제출해야합니다.

중첩 된 모델 양식에서 Railscasts를 확인할 수도 있습니다. 그들은 일대 다 관계를 다루고 있습니다. 여기에 part onepart two이 있습니다. 그들은 꽤 오래되었고, 자바 스크립트 부분은 약간 구식이지만 기본적인 요지는 여전히 정확합니다.

+0

간단하기 때문에, 에밀리 감사합니다! :) – Anero

관련 문제