간단한 has_many 관계를 만들고 양식으로 업데이트하려고합니다. 도움을 미리 감사드립니다.선택 양식에 Has_many를 알아낼 수 없습니다.
모델
class Position < ActiveRecord::Base
#position attributes
has_many :educations, :foreign_key => "position_id"
class Education < ActiveRecord::Base
belongs_to :position
EDUCATION_CHOICES = ([["Undergrad", "0"],["Master", 1],["PHD", 2]])
교육 데이터 모델은 PK (자동), position_id, education_value 및 타임 스탬프를 가지고있다. education_value는 EDUCATION_CHOICES
에서 값을 저장하기위한 것입니다startupfeeder_dev=# select * from educations; id | position_id | education_value | created_at | updated_at ----+-------------+-----------------+----------------------------+---------------------------- 3 | 11 | 1 | 2012-04-27 08:26:28.077517 | 2012-04-27 16:27:50.330082 1 | 12 | 1 | 2012-04-27 00:40:22.868336 | 2012-04-27 16:30:07.123653 2 | 12 | 2 | 2012-04-27 00:45:06.613306 | 2012-04-27 16:30:07.127601 (3 rows)
형태 :
<%= f.select(:education_ids, Education::EDUCATION_CHOICES,{ :prompt => "Please select"},
{ :multiple => true, :size => 5 }) %>
위치 컨트롤러 :
@position = Position.new(params[:position])
표준, 아직 추가 아무것도.
일부 데이터를 수동으로 추가 했으므로 문제가 없습니다.
그러나 업데이트 및 만들기가 올바르게 매핑되지 않습니다.
Processing by PositionsController#create as HTML
매개 변수 :
이
내가 내 로그에 무엇을 얻을 { "위치"=> { "제목"=> "test13", "education_ids"=> [ "", "1" "authenticate_token"=> "XZRsnWTKkpprCOfmekOuXdPFKbZea1bfckCsLgG3/go =", "utf8"=> "\ 342 \ 234 \ 223", "설명"= ""test13 " "} 교육 부하 (0.9ms) 선택"교육 ". *"교육 "에서"교육 "."id "IN (1, 2)내 문제는 내가 가지고있는 f.select에 있다고 생각합니다. : education_ids, 교육 _ 값으로 매핑되어야합니다.
편집 된 양식 코드에 mutli-select –