gpt4 book ai didi

ruby - 没有路由匹配 Controller

转载 作者:数据小太阳 更新时间:2023-10-29 08:54:44 26 4
gpt4 key购买 nike

在我的 Rails 3 应用程序中,我有一条路线在调用 rake 路线时显示如下:

topic_snippets GET /topics/:topic_id/snippets(.:format) {:action=>"index", :controller=>"snippets"}

在 routes.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"}

更新:我发现了另一个问题,其回答似乎暗示上述内容应该有效:Dynamically construct RESTful route using Rails

谢谢
阿南德

最佳答案

好的,我找到了 - Ryan 的评论提供了线索。

我没有传递@topic,这是必需的。如果我删除@topic,它会尝试访问没有路由的/snippets/。在调用此行之前,我将 @topic 设置为有效主题并且它有效。谢谢,瑞安!

关于ruby - 没有路由匹配 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4213276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com