accepts_nested_attributes_for를 사용할 때 조인 모델의 속성을 어떻게 편집합니까?
3 가지 모델이 있습니다 : 링커에 의해 결합 된 주제 및 기사
class Topic < ActiveRecord::Base
has_many :linkers
has_many :articles, :through => :linkers, :foreign_key => :article_id
accepts_nested_attributes_for :articles
end
class Article < ActiveRecord::Base
has_many :linkers
has_many :topics, :through => :linkers, :foreign_key => :topic_id
end
class Linker < ActiveRecord::Base
#this is the join model, has extra attributes like "relevance"
belongs_to :topic
belongs_to :article
end
그래서 토픽 컨트롤러의 "new"액션으로 글을 작성할 때 ...
@topic.articles.build
... 토픽 /new.html.erb에 중첩 된 양식을 만듭니다 ...
<% form_for(@topic) do |topic_form| %>
...fields...
<% topic_form.fields_for :articles do |article_form| %>
...fields...
... Rails는 자동으로 링커를 생성합니다. 이제 내 질문에 대해 : 내 링커 모델에는 "새 주제"양식을 통해 변경할 수있는 속성도 있습니다. 그러나 Rails가 자동으로 생성하는 링커는 topic_id 및 article_id를 제외한 모든 속성에 대해 nil 값을 갖습니다. 다른 링커 속성에 대한 필드를 "new topic"양식에 넣어서 nil이 나오지 않게하려면 어떻게해야합니까?
User을 통해Account사용 aRelationshipA와linker...하지만 나는 새와이 조치가 같은 ... 당신이 될까요 모습에 의미 만들 알아낼 수없는 이유는 무엇입니까?