Rails link_to params.id instead of / id

I had a little problem creating the link.

My opinion:

<%= link_to 'slet', blog_comments_path(c.blog, c), :confirm => 'Er du sikker?', :method => :delete %> 

Output:

 http://localhost:3000/blogs/5/comments.6 

Where should it be:

 http://localhost:3000/blogs/5/comments/6 
+4
source share
3 answers

blog_comments_path is the route for all comments for the blog. if you want just a comment, you should use blog_comment_path (check with rake routes , I may be wrong in the syntax. But you understood this idea.)

+7
source

I think this shorter syntax will work:

 <%= link_to 'slet', [c.blog, c], :confirm => 'Er du sikker?', :method => :delete %> 
+1
source

In my case, I had URLs like users.1 when I wanted users/1
I had to add a line:
resources :users
to routes.rb file

0
source

Source: https://habr.com/ru/post/1395613/


All Articles