1
User
에는 Profession
이 많고, Occupation
은 둘을 연결합니다.다 대 다 관계의 선택 태그가 표시되지 않습니다.
사용할 수있는 직업이있는 선택 메뉴를 게시자의 @user
에 표시하려고합니다. 내가 잘못 여기서 뭐하는 할 수
<%= f.fields_for :occupations do |builder| %>
<%= builder.collection_select(:profession_id, Profession.all, :id, :title) %>
<%= bulder.select :profession_id, Profession.all.collect {|p| [ p.name, p.id ] }, { include_blank: true })) %>
<% end %>
<%= select("occupation", "profession_id", Profession.all.collect {|p| [ p.title, p.id ] }, { include_blank: true }) %>
: 디버깅하는
나는 다음과 같은 세 가지 변화를 시도했습니다,하지만 코드가 전혀 렌더링되지 않습니다 (양식의 나머지 부분은 아무런 문제가 없습니다)? 오류 메시지가 표시되지 않습니다. select 태그에 대한 html이 없습니다.
class User < ActiveRecord::Base
has_many :occupations, dependent: :destroy
has_many :professions, through: :occupations
accepts_nested_attributes_for :occupations
end
class Profession < ActiveRecord::Base
has_many :occupations, dependent: :destroy
has_many :users, through: :occupations
end
class Occupation < ActiveRecord::Base
belongs_to :user
belongs_to :profession
end
나는 이것을했고 지금은 뭔가 * 일어나고있다 - 그것이 좋은지 나쁜지 모르겠다. 다시로드 할 때 다음 오류가 발생합니다. "정의되지 않은 메소드'occupations_path '". 나는 이것이 별도의 질문이라는 것을 알고 있지만 왜 occupations_path를 렌더링하는 것 같습니까? –
@FellowStranger 거의 확실하게'fields_for'에 대한 목표 경로를 만들고 그렇게하기위한 경로 도우미가 없다는 것을 발견했습니다. 무슨 일이 일어나고 있는지'레이크 루트 (rake routes) '를 사용하십시오. 'fields_for' 타겟은 Occupation 컨트롤러의'PUT'과'POST' 메소드와 일치해야합니다. – Gene
별도의 경로가 필요한 'fields_for' 부분에 대해 혼란스러워해도 입력을 주셔서 감사합니다.'fields_for '를 사용하면 관련 모델이 기본 양식 객체 ('@ user')에 중첩됩니다.) '라우팅을 상속합니까? –