开发者

No route matches controller

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开发者_如何学Go_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


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

<%= send(eval("topic_#{@name}_path"), @topic)%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜