【问题标题】:Namespaced subdomain controllers and custom layout命名空间子域控制器和自定义布局
【发布时间】:2014-11-08 10:06:01
【问题描述】:

我命名了我的子域,现在我正在尝试为该子域加载自定义布局。如果不在我的app/controllers/student/base_controller.rb 中使用它,我怎么能做到这一点:

class Student::BaseController < ApplicationController
  layout 'student'
end

我试图将我的 application.html.erb 文件复制到 app/views/student/layouts 中,但我读过它不起作用,所以我将它复制到 app/views/layouts/student/ 中,但它仍然不起作用。我做错了什么?

谢谢大家!

【问题讨论】:

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


    【解决方案1】:

    我认为布局不受命名空间的限制

    --

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

    class Admin::ApplicationController < InheritedResources::Base
    
        #Layout
        layout "admin"
    
        ...
    

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-12
        • 1970-01-01
        • 2018-02-10
        • 1970-01-01
        • 1970-01-01
        • 2012-07-08
        相关资源
        最近更新 更多