没有路由匹配控制器
在我的 Rails 3 应用程序中,我有一条在调用 rake 路线时显示如下的路线:
topic_snippets GET /topics/:topic_id/snippets(.:format) {:action=>"index", :controller=>"snippets"}
在 paths.rb 中
resources :topics do
member do
get 'get_topics'
end
resources :snippets, :only => [:index]
end
在我看来,我按如下方式引用该路线(其中 @name =“snippets”):
<%= send("topic_#{@name}_path")%>
执行上一行时,我收到以下路由错误,不知道为什么:
No route matches {:controller=>"snippets"}
更新:我发现了另一个问题,其响应似乎暗示上述内容应该有效:使用 Rails 动态构建 RESTful 路由
谢谢
阿南德
In my rails 3 app, I have a route which shows up as follows while calling rake routes:
topic_snippets GET /topics/:topic_id/snippets(.:format) {:action=>"index", :controller=>"snippets"}
In routes.rb
resources :topics do
member do
get 'get_topics'
end
resources :snippets, :only => [:index]
end
In my view, I am referencing this route as follows (where @name = "snippets"):
<%= send("topic_#{@name}_path")%>
When executing the previous line, I get the following routing error, not sure why:
No route matches {:controller=>"snippets"}
Update: I found another question whose responses seem to imply that the above should work: Dynamically construct RESTful route using Rails
Thanks
Anand
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了 - Ryan 的评论提供了线索。
我没有传递@topic,这是必需的。如果我删除@topic,它会尝试访问没有路由的/snippets/。在调用此行之前,我将 @topic 设置为有效主题,并且它有效。谢谢,瑞安!
OK, I found it - Ryan's comment provided the clue.
I wasnt passing in @topic, which is required. If I remove @topic, it tries to just get at /snippets/ which doesn't have a route. I set @topic to a valid topic before calling this line and it works. Thanks, Ryan!
你尝试过吗
Have you tried