ruby-on-rails – 将控制器路由到命名空间:admin to / admin
发布时间:2020-12-17 04:18:06 所属栏目:百科 来源:网络整理
导读:我觉得这可能是一个愚蠢的问题,但现在已经很晚了,我的脑袋正在融化……所以我很感激你的帮助. 我正在尝试将网址http://localhost:3000/admin映射到仪表板控制器,但我很失败.也许这甚至不可能或完全错误的想法,但无论如何我的路线看起来像这样,是的 namespace
我觉得这可能是一个愚蠢的问题,但现在已经很晚了,我的脑袋正在融化……所以我很感激你的帮助.
我正在尝试将网址http://localhost:3000/admin映射到仪表板控制器,但我很失败.也许这甚至不可能或完全错误的想法,但无论如何我的路线看起来像这样,是的 namespace :admin do resources :dashboard,{ :only => [:index],:path => '' } ... end 和我简单的dashboard_controller.rb class Admin::DashboardController < ApplicationController before_filter :authenticate_user! filter_access_to :all def index @schools = School.all end end 我的视图位于views / admin / dashboard / index.html.erb中 感谢任何输入 解决方法
如果你要做的就是路由/管理到那个仪表板控制器,那么你就是通过命名它来使它过于复杂.
使用类似嵌套资源的命名空间意味着它将是/ admin / dashboards用于:index操作而不是具有干净/管理路由(并且您可以通过在命令行运行rake路由以获取您的列表来验证路由). 选项1:您打算将其命名为 # putting this matched route above the namespace will cause Rails to # match it first since routes higher up in the routes.rb file are matched first match :admin,:to => 'admin/dashboards#index' namespace :admin do # put the rest of your namespaced resources here ... end 选项2:您并不是故意将其命名为 路线: match :admin,:to => 'dashboards#index' 控制器: # Remove the namespace from the controller class DashboardController < ApplicationController ... end 视图应该移回: views/dashboards/index.html.erb 更多信息:http://guides.rubyonrails.org/routing.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |