No route matches [POST] "/posts/39/comments/41" in rails

Asked 2 months ago, Updated 2 months ago, 2 views

I'd like to see the number I counted in rails, but it says No route matches [POST] "/posts/39/comments/41".

Please help me.I look forward to your kind cooperation.

routes

Rails.application.routes.drawdo

  get 'static_pages/about'

  get'static_pages/privacy'

  get 'static_pages/agreement'

  get 'static_pages/organization'

  delete 'users', to: 'users#destroy'

  resources —users do
    member do
      get —activate
    end
  end

    get 'registrations/new'
  resource:registrations, only:[:new,:create]
  resource:sessions, only: [:new,:create,:destroy]
  resource:settings,only:[:edit,:update]
  get 'settings/static_pages/about', to: 'static_pages#about'
  resources:users,only:[:index,:show,:new]
  root to: 'posts#index'
  resources —users
  resources —posts do
    resources —Comments do
      resources:like, only:[:create,:destroy]
    end
  end
  resources —genres
  get 'attensions', to: 'attensions#index'
  # For details on the DSL available with this file, see http://guides.rubyonrails.org/routing.html
end

show View

<div class="container">
    <div class="row">
    <div class="answer">
      <h4>Answer</h4>
      <%[email protected] y?%>
      <ul>
        <%@post.comments.each do | comment | %>
          <%[email protected]==comment.user%>
            <%[email protected]?%>
              <p>Questioner </p>
            <%else%>
              <p>Questioner: <%[email protected]%>/p>
            <%end%>
          <%else%>
            <p> Respondents: <%[email protected]%>/p>
          <%end%>
      <li>
        <%=comment.body%>
        <%[email protected]==current_user%>
          <%=link_to 'Delete Answer',
            post_comment_path(@post, comment),
            method: —delete,
            class: 'command',
            data: {confirm:'Do you want to delete the answer?' }%>
        <%end%>
      </li>  
        <div class="evalation">
          <%if current_user.already_liked?(@post)%>
            <%=button_to'♡', post_comment_path(@post,comment), method::update,class:"button"%>%=comment.Evaluation%>
          <%else%>
            <%if comment.likes.count == 0%>
              <%=button_to'♡', post_comment_path(@post,comment), method::update,class:"button"%>
            <%else%>
              <%=button_to'♡', post_comment_path(@post,comment), name: "promote", class: "button"%>%=comment.Evaluation%>
            <%end%>
          <%end%>
        </div>
      <%end%>
      </ul>
      <%end%> 
      <%=form_for([@post,@post.comments.build])do|f|%>
      <p>
        <%=f.text_field:body, class:"show-content"%>
      </p>
      <p>
        <%=f.submit "Answer", class: "comment"%>
      </p>
      <%end%>
    </div>
    </div>
  </div>
  </div>
</div>

class CommentsController<ApplicationController
    def create
        @post=Post.find (params[:post_id])
        @post.comments.create(comment_params.merge(user_id:current_user.id)) 
        redirect_to post_path(@post)
    end

    def destroy
        @post=Post.find (params[:post_id])
        @[email protected] (params[:id])
        @ comment.destroy
        redirect_to post_path(@post)
    end

    default update
        if params [:promote] then
            @post.comments.increment!(:Evaluation, by = 0)
            @post.comments.touch
            redirect_to post_comment_path(@post,@comment)
        end
    end

    private
        def comment_params
            param.require(:comment).permit(:body)
        end
            # Use callbacks to share common setup or constraints between actions.
        default_comment
            @post.comments=Comment.find (params[:id])
        end

end

rails routes

Prefix Verb URI Pattern users#destroy
              activate_user GET/users/:id/activate(.:format)users#activate
                            GET/users(.:format)users#index
                            POST/users(.:format)users#create
                   new_user GET/users/new(.:format)users#new
                  edit_user GET/users/:id/edit(.:format)users#edit
                       user GET/users/:id(.:format)users#show
                            PATCH/users/:id(.:format)users#update
                            PUT/users/:id(.:format)users#update
                            DELETE/users/:id(.:format)users#destroy
                                      users#index
                            GET/users/new(.:format)users#new
                            GET/users/:id(.:format)users#show
                       root GET/posts#index
                            GET/users(.:format)users#index
                            POST/users(.:format)users#create
                            GET/users/new(.:format)users#new
                            GET/users/:id/edit(.:format)users#edit
                            GET/users/:id(.:format)users#show
                            PATCH/users/:id(.:format)users#update
                            PUT/users/:id(.:format)users#update
                            DELETE/users/:id(.:format)users#destroy
         post_comment_likes POST/posts/:post_id/comments/:comment_id/likes(.:format)like#create
          post_comment_like DELETE/posts/:post_id/comments/:comment_id/likes/:id(.:format)like#destroy
              post_comments GET/posts/:post_id/comments(.:format)comments#index
                            POST/posts/:post_id/comments(.:format) comments#create
           new_post_comment GET/posts/:post_id/comments/new(.:format)comments#new
          edit_post_comment GET/posts/:post_id/comments/:id/edit(.:format)comments#edit
               post_comment GET/posts/:post_id/comments/:id(.:format)comments#show
                            PATCH/posts/:post_id/comments/:id(.:format)comments#update
                            PUT/posts/:post_id/comments/:id(.:format)comments#update
                            DELETE/posts/:post_id/comments/:id(.:format)comments#destroy
                      posts GET/posts(.:format) posts#index
                            POST/posts(.:format) posts#create
                   new_post GET/posts/new(.:format)posts#new
                  edit_post GET/posts/:id/edit(.:format)posts#edit
                       post GET/posts/:id(.:format)posts#show
                            PATCH/posts/:id(.:format) posts# update
                            PUT/posts/:id(.:format) posts# update
                            DELETE/posts/:id(.:format)posts#destroy
                     genres GET/genres(.:format)   

ruby-on-rails

2022-09-30 13:54

1 Answers

Try replacing post_comment_like instead of post_comment_path.


2022-09-30 13:54

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.