2014-09-15 7 views
0

chap_comment_controller.rb 렌더링되지는 레일 - 부분적인 형태로 hidden_field - erroring 또는

def create 
    @chap_comment = current_user.chap_comments.build(chap_comment_params) 
    if @chap_comment.save 
     flash[:success] = "Comment created!" 
    else 
     render fallovercoswrong 
    end 
    end 

가 나는 부분이 포함 - _chap_comment_form.html.erb

<%= form_for(@chap_comment) do |f| %> 
    <%= f.text_area :comment_text, placeholder: "Comment..." %> </div> 
    <%= f.hidden_field :chapter_id, @chapter.id %> 
    <%= @chapter.id %>is chapter id 
    <%= f.submit "Post" %> 
<% end %> 

: chap_comment의 belongs_to : 사용자 및 : 장

숨겨진 필드로 인해 문제가 발생합니다. 위의 코드는

<%= f.hidden_field_tag ..... 

반환

undefined method `hidden_field_tag' for #<ActionView::Helpers::FormBuilder:0x007fa33165f7a8> 

<%= hidden_field_tag ...... 

가 자동으로 렌더링에 숨겨진 필드를 넣어 실패로 라인을 변경 오류

undefined method `merge' for 1:Fixnum 

을 반환 html. 이 문제를 해결하는 가장 좋은 방법은 무엇입니까?

답변

2

바꾸기 :

<%= f.hidden_field :chapter_id, @chapter.id %> 

으로 :

<%= f.hidden_field :chapter_id, value: @chapter.id %> 

hidden_field는 두 번째 인수

+0

네 같은 해시를 기대 - 그 감사를, 나는 문서를 오해. – RADan