开发者

No route matches scoped resources

  1. rails new example
  2. rails g scaffold widget
  3. rake db:migrate
  4. Edit routes.rb as follows: scope ":year" do resources :widgets end
  5. curl http://0.0.0.0:3000/2011/widgets is successful
  6. echo "Widget.new.save" | rails c
  7. curl http://0.0.0.0:3000/2011/widgets/1 is successful
  8. But now curl http://0.0.0.0:3000/2011/widgets fails with the following error:

No route matches {:action=>"show", :controller=>"widgets", :year=>#<Widget id: 1 .. etc.

Why does it think the action is "show"? Why does it think the year i开发者_StackOverflows a widget instance? Very strange. I get the same result in rails 3.0.9 and 3.1.0.rc6.

Thanks in advance for your help.


try

resources :widgets

(with S in the end)

UPD: in index.html.erb instead of

link_to widget 

use smth like

link_to widget_path(widget, :year => 2011)

or

link_to widget_path(2011, widget)
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜