rails路由问题

时间:2011-01-31 21:18:46

标签: ruby-on-rails routing

我的路由配置中有以下内容:

resources :users do
  resources :apps, :controller => :user_apps
end

rake routes包括以下内容:

    user_apps GET    /users/:user_id/apps(.:format)          {:action=>"index", :controller=>"user_apps"}
    user_apps POST   /users/:user_id/apps(.:format)          {:action=>"create", :controller=>"user_apps"}
 new_user_app GET    /users/:user_id/apps/new(.:format)      {:action=>"new", :controller=>"user_apps"}
edit_user_app GET    /users/:user_id/apps/:id/edit(.:format) {:action=>"edit", :controller=>"user_apps"}
     user_app GET    /users/:user_id/apps/:id(.:format)      {:action=>"show", :controller=>"user_apps"}
     user_app PUT    /users/:user_id/apps/:id(.:format)      {:action=>"update", :controller=>"user_apps"}
     user_app DELETE /users/:user_id/apps/:id(.:format)      {:action=>"destroy", :controller=>"user_apps"}

但是,当我尝试访问例如user_apps_path(1,2)时,我得到/users/1/apps.2而不是/users/1/apps/2

我哪里错了?

我正在使用rails 3。

1 个答案:

答案 0 :(得分:2)

正确的路由是user_app_path(1,2)复数版本转到index操作,第二个参数是请求的格式/扩展名。