레일을 학습하는 동안 일부 stackoverflow 기능을 모방하려고합니다. Particulary Q에 관심이 있어요 & 질문에 많은 답변 및 댓글이있는 경우 시스템이 질문 및 답변에 속합니다. 그래서 연관과 중첩 된 속성으로 시작했습니다. 중첩 된 속성에 대한 학습 소스는 railcast.com이고 Ryan은 new.html.erb (설문 조사)에 양식 (질문, 답변)을 추가하고 있지만 show.html.erb에 추가하고 싶습니다. 내가 그걸 할 때 나는 뭔가를 게시하지 않는 한 괜찮아 보인다. 처음 답변을 제출 한 후 질문 쇼는 게시 된 응답, 빈 응답 양식 및 텍스트 응답 양식으로 렌더링됩니다. 그래서 전반적으로 저는 답과 두 가지 형태 (하나는 텍스트가 비어 있습니다)를 가지고 있습니다. 답변을 위해 빈 양식 만 렌더링하려면 어떻게해야합니까?fields_for 쇼보기에서 중첩 된 속성
show.html.erb
@question.answers.each do |answer|
answer.body
end
form_for @question do |f|
f.fields_for :answers do |builder|
builder.text_area :body
end
f.submit
end
question.rb
has_many :answers
accept_nested_attributes_for :answer
accept_nested_attributes_for :comment
answer.rb
belongs_to :question
accept_nested_attributes_for :comment
comment.rb
belongs_to :answer
belongs_to :question
questions_controller.rb
def show
@question = Question.find(params[:id])
@question.answers.build
end
f.fields_for'와'fields_for' 라인을 교체하려고 : 답변, @의 question.answers.build가 할 | 빌더 |' –