0

우리는 최소한의 중첩 된 Comment's Controller에 대해 이야기하고 있습니다.유효성 검사를 위반할 때 NoMethodError

검증 코멘트의 작품을 편집, 이제 validates :body, :presence => true

, 그리고 내가 검증을 새로운 주석을 작성하고 어기면 정상적으로 표시됩니다. 나는 일반적으로 내가 몸에 대해 오류가 발생한다 코멘트를 편집하고 자신의 몸을 삭제할 때

내 문제 대신 나는 NoMethodError in Comments#update

문제 확장 => 일반적으로 내가 성공적으로 편집 할 때를 얻을 수있다 댓글 (http://localhost:3000/s/38/comments/11/edit)은 @screen http://localhost:3000/s/38으로 나를 리디렉션합니다. 하지만 내가 몸을 비우고 제출하려고하면 오류가 표시되는 대신 http://localhost:3000/s/38/comments/11으로 리디렉션됩니다.

enter image description here

내가 무엇을 놓치고?

감사관 :

def update 
    respond_to do |format| 
     if @comment.update(comment_params) 
     format.html { redirect_to @comment.screen, notice: 'Comment was successfully updated.' } 
     format.json { head :no_content } 
     else 
     format.html { render action: 'edit' } 
     format.json { render json: @comment.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

내 편집 양식 :

<%= form_for([@screen, @comment]) do |f| %> 

    <div class="panel panel-default"> 
    <div class="panel-heading"> 
     <h1>Edit your Comment</h1> 
     <% if @comment.errors.any? %> 
     <div id="error_explanation"> 
      <h3><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h3> 

      <ul> 
      <% @comment.errors.full_messages.each do |msg| %> 
       <li><%= msg %></li> 
      <% end %> 
      </ul> 
     </div> 
     <% end %> 
    </div> 

    <div class="panel-body"> 
     <div class="form-group"> 
     <%= f.label :body, "Comment" %> 
     <%= f.text_area :body, autofocus: true, class: "form-control" %> 
     </div> 
    </div> 

    <div class="panel-footer"> 
     <%= f.submit "Edit Comment", class: "btn btn-primary" %> 
     <%= link_to "Back", @screen, class: "btn btn-primary" %> 
    </div> 
    </div> 

<% end %> 

내 경로 : 그건 항상 사용됩니다 같은 다형성 경로를 사용하는

resources :screens, :path => 's' do 
    resources :comments 
    member do 
     get :like 
     get :unlike 
    end 
    end 
screen_comments GET /s/:screen_id/comments(.:format)   comments#index 
        POST /s/:screen_id/comments(.:format)   comments#create 
    new_screen_comment GET /s/:screen_id/comments/new(.:format)  comments#new 
edit_screen_comment GET /s/:screen_id/comments/:id/edit(.:format) comments#edit 
     screen_comment GET /s/:screen_id/comments/:id(.:format)  comments#show 
        PATCH /s/:screen_id/comments/:id(.:format)  comments#update 
        PUT /s/:screen_id/comments/:id(.:format)  comments#update 
        DELETE /s/:screen_id/comments/:id(.:format)  comments#destroy 
+0

관련 경로 정의를 표시 할 수 있습니까? – vee

+0

업데이트 된 질문. –

+0

'rake routes'를하고 그 경로가 있는지 확인할 수 있습니까? – geekazoid

답변

0

양식 새로운 기록을위한 복수화 된 경로. 내 양식에 명시해야했습니다 :

form_for([@user, @profile], :url => user_profile_path(@user)) 
관련 문제