Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails link_to params .id instead of /id

I am having a small problem creating a link.

My view:

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

Output:

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

Where it should by:

http://localhost:3000/blogs/5/comments/6
like image 348
Rails beginner Avatar asked Feb 09 '12 14:02

Rails beginner


2 Answers

blog_comments_path is the route for all comments for a blog. if you want just a comment, you have to use blog_comment_path (check with rake routes, I might be wrong with the syntax. But you get the idea.)

like image 68
ksol Avatar answered Nov 06 '22 19:11

ksol


Had the same problem, because in my routes I had

resource :products

and not

resources :products

Don't forget the plural ;)

And always check your routes :)

like image 25
OBrooks Avatar answered Nov 06 '22 18:11

OBrooks