ユーザーをグループとサブグループに分割し、各サブグループにカスタマイズされたサイトを提供する Rails アプリを作成しようとしています。これを行う最も簡単な方法は、名前付きパラメーターを使用してスコープを作成することだと考えました。
scope ":group/:subgroup/" do
devise_for :users
resources :users
end
"rake routes" は次のように生成します:
users GET /:group/:subgroup/users(.:format) {:action=>"index", :controller=>"users"}
POST /:group/:subgroup/users(.:format) {:action=>"create", :controller=>"users"}
new_user GET /:group/:subgroup/users/new(.:format) {:action=>"new", :controller=>"users"}
edit_user GET /:group/:subgroup/users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
user GET /:group/:subgroup/users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /:group/:subgroup/users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /:group/:subgroup/users/:id(.:format) {:action=>"destroy", :controller=>"users"}
link_to を使用する場合を除いて、完全に機能します。
link_to current_user.name, current_user
次に、このエラーがスローされます
ActionController::RoutingError in Users#index
Showing C:/Rails/MyApp/app/views/users/_my_list.html.haml where line #8 raised:
No route matches {:action=>"show", :controller=>"users", :group=>#<User id: 7, email: "username@domain.com", encrypted_password: "$2a$10$GdZeC0b4VaNxdsDXP...", password_salt: "$2a$sj$88gm0nttYE.7a4IHi.BNO", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 86, current_sign_in_at: "2011-08-05 17:18:19", last_sign_in_at: "2011-08-05 00:14:26", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", confirmation_token: nil, confirmed_at: "2010-12-09 23:08:54", confirmation_sent_at: "2010-12-09 23:08:36", failed_attempts: 0, unlock_token: nil, locked_at: nil, created_at: "2010-12-09 23:08:36", updated_at: "2011-08-05 17:18:19", name: "UserOne">}
もちろん、8 行目は link_to を使用しようとした場所です。私の推測では、link_to はスコープを無視しており、current_user が :group パラメータに詰め込まれていることを説明しています。これが起こらないようにする方法はありますか、それともこの問題全体について完全に間違っていますか?