命名空间子域控制器和自定义布局

时间:2014-09-14 22:22:07

标签: ruby-on-rails ruby-on-rails-4 namespaces subdomain

我命名了我的子域名,现在我正在尝试为该子域名加载自定义布局。如果不在我的app/controllers/student/base_controller.rb

中使用它,我怎样才能做到这一点
class Student::BaseController < ApplicationController
  layout 'student'
end

我尝试在application.html.erb内复制我的app/views/student/layouts文件,但我读过这不起作用,所以我将其复制到app/views/layouts/student/内,但仍然无效。我做错了什么?

谢谢大家!

2 个答案:

答案 0 :(得分:1)

调用方法layout时,传递布局文件的名称,而不是其目录。所以在你的情况下,布局应该是app/views/layouts/student.html.erb。在此处阅读有关布局的更多信息:http://guides.rubyonrails.org/layouts_and_rendering.html

答案 1 :(得分:0)

我认为布局不受命名空间

的限制

-

以下是我们使用的一些实时代码:

class Admin::ApplicationController < InheritedResources::Base

    #Layout
    layout "admin"

    ...

这使我们能够调用app/views/layouts/admin.html.erb

相关问题