ruby-on-rails – 将控制器路由到命名空间:admin to / admin

我觉得这可能是一个愚蠢的问题,但现在已经很晚了,我的脑袋正在融化……所以我很感激你的帮助.

我正在尝试将网址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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...