Namespaced Rails 'root to:' route not working as expected
我正在阅读路线(外部路线)中的Rails指南,并且看到了以下内容:
You can also use root inside namespaces and scopes as well. For
example:
1 2 3 4 5 | namespace :admin do root to:"admin#index" end root to:"home#index" |
我正在尝试复制此代码以查看其工作方式,因此在我的config / routes.rb文件中,我具有以下代码:
1 2 3 | namespace :admin do root to: 'users#index' end |
我希望能够访问\\'localhost:3000 / admin \\'并被定向到users#index页面,但是我收到了错误消息\\'uninitialized constant Admin \\'。
我误解了示例代码应该做什么,还是我写的东西有问题?
namespace:admin,将把您路由到控制器Admin :: UsersConroller。如果要将/ admin路由到UsersConroller,则应使用范围而不是名称空间。
1 2 3 | scope '/admin' do root to: 'users#index' end |
您可以在此处了解更多信息