rails new example
rails g scaffold widget
rake db:migrate
- Edit routes.rb as follows:
scope ":year" do resources :widgets end
curl http://0.0.0.0:3000/2011/widgets
is successfulecho "Widget.new.save" | rails c
curl http://0.0.0.0:3000/2011/widgets/1
is successful- 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)
精彩评论