简体   繁体   English

Rails link_to params .id而不是/ id

[英]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

blog_comments_path is the route for all comments for a blog. blog_comments_path是博客所有评论的路线。 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.) 如果你只想要一个评论,你必须使用blog_comment_path (检查rake routes ,我可能错误的语法。但你明白了。)

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 :) 并始终检查您的路线:)

我认为这种较短的语法可行:

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

In my case I had urls like users.1 when I wanted users/1 在我来说,我有喜欢的网址users.1时,我想users/1
I had to add the line: 我不得不添加一行:
resources :users
to my routes.rb file 到我的routes.rb文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM