컨트롤러와 뷰가 각각 두 가지 인 모델이 있습니다 (Profile
및 Comment
).하나의보기에서 두 모델의 데이터 표시
내 응용 프로그램의 전체보기 (전체 웹 페이지)는 Profile
show.html.erb
입니다. 이 페이지에서 사용자는 belongs_to
a Profile
인 설명을 작성할 수 있어야합니다.
표준 /comments/new
페이지로 이동하지 않고 어떻게이 작업을 수행 할 수 있습니까?
편집 :
def create @profile = profile.find(params[:profile_id]) @comment = @profile.comments.create(params[:comment]) redirect_to profile_path(@profile)
CommentController
<%= simple_form_for([@profile, @profile.comment.build], html: {class: "form-inline"}) do |f| %>
<%= f.error_notification %>
<%= f.input :description, label: false, placeholder: 'Create an comment', input_html: { class: "span4" } %>
<%= f.submit 'Submit', class: 'btn btn-small'%>
<% end %>
을 그리고이 오류 받고 있어요 : 레일 가이드를 따른 후, 나는 구현
undefined method `comment' for #<Profile:
고정을 : 빌드 문에서 필요한 의견은 당신이해야 할 모든 프로필 # 쇼에 코멘트 양식 코드를 추가입니다
@profile.comments.build
다음을보십시오 : http://guides.rubyonrails.org/getting_started.html#generating-a-controller – siekfried
위의 오류를 참조하십시오 – mnort9
양식 선언에's'을 (를) 잊어 버렸습니다 :'<% = simple_form_for ([@ profile, @ profile.comments.build] ' – siekfried