Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3.2 RubyonRails中的路由和名称空间_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails 3.2 RubyonRails中的路由和名称空间

Ruby on rails 3.2 RubyonRails中的路由和名称空间,ruby-on-rails-3.2,Ruby On Rails 3.2,Ruby on Rails应用程序代码的一部分: #routes.rb namespace :admin do root :to => 'admin#index' resources :orders, :products end #controllers/admin/admin_contrller.rb class Admin::AdminController < Appli

Ruby on Rails应用程序代码的一部分:

    #routes.rb
        namespace :admin do
              root :to => 'admin#index'
              resources :orders, :products
        end

  #controllers/admin/admin_contrller.rb
    class Admin::AdminController < ApplicationController
       def index

       end
    end
索引视图位于views/admin/index.html.haml中。但是,它没有找到它http://localhost:3000/admin,缺少模板。它仅在位于views/admin/admin/index.html.haml中时才能找到它


我做错了什么?我应该怎么做才能在views/admin/index.html.haml中找到视图?

您已经创建了namespace:admin并将根路径和订单资源放在那里。根路径指向AdminController的索引ADAction。通过这种配置,rails将在views/admin/admin/index.html.haml下查找index.html.haml视图,其中第一个admin是名称空间,第二个是控制器的目录

你没做错什么。这就是rails的工作方式

我建议,与其尝试在views/admin/index.html.haml中查找视图,不如简单地将AdminController名称更改为DashboardController,并将BaseController创建为admin/directory下所有控制器的基类

app/controllers/admin/admin\u controller.rb

class Admin::BaseController < ApplicationController
  #auth etc.
end
class Admin::DashboardController < Admin::BaseController

end

您已经创建了namespace:admin,并将根路径和订单资源放在那里。根路径指向AdminController的索引ADAction。通过这种配置,rails将在views/admin/admin/index.html.haml下查找index.html.haml视图,其中第一个admin是名称空间,第二个是控制器的目录

你没做错什么。这就是rails的工作方式

我建议,与其尝试在views/admin/index.html.haml中查找视图,不如简单地将AdminController名称更改为DashboardController,并将BaseController创建为admin/directory下所有控制器的基类

app/controllers/admin/admin\u controller.rb

class Admin::BaseController < ApplicationController
  #auth etc.
end
class Admin::DashboardController < Admin::BaseController

end

有没有办法手动设置查看路径?只需编辑我的答案并添加替代方案即可满足您的要求;有没有办法手动设置查看路径?只需编辑我的答案并添加替代方案即可满足您的要求;