1
  1. rails new example
  2. rails g scaffold widget
  3. rake db:migrate
  4. routes.rb を次のように編集します。scope ":year" do resources :widgets end
  5. curl http://0.0.0.0:3000/2011/widgets成功しています
  6. echo "Widget.new.save" | rails c
  7. curl http://0.0.0.0:3000/2011/widgets/1成功しています
  8. しかし、次のエラーで失敗します。curl http://0.0.0.0:3000/2011/widgets

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

アクションが「表示」であると考えるのはなぜですか?年がウィジェットインスタンスであると考えるのはなぜですか? 非常に奇妙な。Rails 3.0.9 と 3.1.0.rc6 でも同じ結果が得られます。

よろしくお願いします。

4

1 に答える 1

2

試す

resources :widgets

(最後に S を付けます)

UPD: index.html.erb ではなく

link_to widget 

のように使う

link_to widget_path(widget, :year => 2011)

また

link_to widget_path(2011, widget)
于 2011-08-27T09:53:21.703 に答える