ruby - Rails 'link_to' giving an incorrect path to delete a Nested Resource -
i made simple blog application in rails , when tried giving link delete comment rails gave me incorrect link
<a data-method="delete" href="/forums/27/comment.7" rel="nofollow">delete</a> this gave me error
no route matches [delete] "/forums/27/comment.7" but when changed
<a data-method="delete" href="/forums/27/**comments/7**" rel="nofollow">delete</a> by chrome's inspect deleted comment. how generate correct link ?
controller
def destroy @comment.destroy redirect_to :back end private def find_forum @forum = forum.find(params[:forum_id]) end def set_comment @comment = comment.find(params[:id]) end show.html.haml
- @forum.comments.each |c| = c.user.firstname = c.comment - if user_signed_in? - if c.user == current_user = link_to "delete", [@forum, c], method: :delete routes
prefix verb uri pattern controller#action forum_like put /forums/:forum_id/like(.:format) forums#like forum_unlike put /forums/:forum_id/unlike(.:format) forums#unlike forum_comment put /forums/:forum_id/comment(.:format) forums#comment forum_comments /forums/:forum_id/comments(.:format) comments#index post /forums/:forum_id/comments(.:format) comments#create new_forum_comment /forums/:forum_id/comments/new(.:format) comments#new edit_forum_comment /forums/:forum_id/comments/:id/edit(.:format) comments#edit /forums/:forum_id/comments/:id(.:format) comments#show patch /forums/:forum_id/comments/:id(.:format) comments#update put /forums/:forum_id/comments/:id(.:format) comments#update delete /forums/:forum_id/comments/:id(.:format) comments#destroy forums /forums(.:format) forums#index post /forums(.:format) forums#create new_forum /forums/new(.:format) forums#new edit_forum /forums/:id/edit(.:format) forums#edit forum /forums/:id(.:format) forums#show patch /forums/:id(.:format) forums#update put /forums/:id(.:format) forums#update delete /forums/:id(.:format) forums#destroy new_user_session /users/sign_in(.:format) devise/sessions#new user_session post /users/sign_in(.:format) devise/sessions#create destroy_user_session delete /users/sign_out(.:format) devise/sessions#destroy user_password post /users/password(.:format) devise/passwords#create new_user_password /users/password/new(.:format) devise/passwords#new edit_user_password /users/password/edit(.:format) devise/passwords#edit patch /users/password(.:format) devise/passwords#update put /users/password(.:format) devise/passwords#update cancel_user_registration /users/cancel(.:format) registrations#cancel user_registration post /users(.:format) registrations#create new_user_registration /users/sign_up(.:format) registrations#new edit_user_registration /users/edit(.:format) registrations#edit patch /users(.:format) registrations#update put /users(.:format) registrations#update delete /users(.:format) registrations#destroy root / forums#index
you need use forum_comment_path helper:
= link_to "delete", forum_comment_path(@forum, c), method: :delete
Comments
Post a Comment