을 나는 세 가지 모델는 자신의 속성을 가진 조인 테이블에 accepts_nested_attributes_for 사용 - 중복 행
class Outbreak < ActiveRecord::Base
has_many :incidents, :dependent => :destroy
has_many :locations, :through => :incidents
accepts_nested_attributes_for :incidents, :allow_destroy => true
accepts_nested_attributes_for :locations, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
class Incident < ActiveRecord::Base
belongs_to :outbreak
belongs_to :location
end
class Location < ActiveRecord::Base
has_many :incidents
has_many :outbreaks, :through => :incidents
accepts_nested_attributes_for :incidents, :allow_destroy => true
end
형태의 매개 변수 (레일 2.3.8) 다음 한 것은 괜찮을 것 같다
"outbreak"=> { "locations_attributes"=> { "0"=> { "lon"=> "1.39", "placename"=> "wetwe", "hpu_id"=> "15", "postcode" => ","address_3 "=>" ","지역 "=" "1" = ""0 "=> {"subtype_id "=>"7 ","category_id "=>"1 ","detail "=>" " , "subcategory_id"=> "2"}} } }
Outbreak가 저장되면 인시던트 테이블 (조인 테이블)에 3 행이 생성되고 비상 발생 및 위치 테이블에는 하나의 행이 생성됩니다. - 어떻게 그냥해야 할
id outbreak_id location_id category_id subcategory_id subtype_id detail created_at updated_at
57 23 NULL 1 2 7 2010-11-25 14:45:18.385905 2010-11-25 14:45:18.385905
58 23 27 NULL NULL NULL NULL 2010-11-25 14:45:18.39828 2010-11-25 14:45:18.39828
59 23 27 NULL NULL NULL NULL 2010-11-25 14:45:18.403051 2010-11-25 14:45:18.403051
이 때문에 매개 변수의 형식 중 하나 또는 방법 accepts_nested_attributes_for 여러이어야합니다 다음과 같이 사건 테이블에
행은 완전히 PARAMS에서 채워지지 않습니다 인시던트 테이블에 모든 매개 변수 정보가있는 단일 행이 입력됩니까?
것을 포기하고 도움을 인터넷에 게시하기 전에 더 많은 노력을 나에게 가르쳐주지 ^^ 난 내 자신의 질문에 대답했습니다 지금까지 이번 주
감사합니다 이것에 대한 많은 도움이 될 수 있습니다뿐만 아니라 통해 ...하지만 당신이 작업을 생성하여 게시 할 수 있으며, 가능한 경우 양식 (정보 제공의 목적으로 만 사용)? – tbk
물론 뭔가를 올려 놓으려고 노력할 것입니다 - 양식은 abit complex (중첩 된 부분 수)이므로 새로운 답으로 게시 할 것입니다. – Pasted