未定义的方法`布局'为

时间:2015-10-22 08:49:37

标签: ruby-on-rails ruby-on-rails-3 layout ruby-on-rails-3.2

我的class Site::BaseController < ApplicationController

中有方法
before_filter :check_layout

   def check_layout
    if @user.site_theme == 'hometastic'
      layout 'hometastic'
    else
      layout 'agent'
    end
  end

当我只做

layout 'agent'  

它完美无缺

但是当我添加before_filter时,我有undefined method layout for

Rails 3.2.16

有什么建议吗?  error screen

3 个答案:

答案 0 :(得分:2)

您可以使用Rails将在处理请求时对其进行评估的符号。 Guides

layout :themed_layout

def themed_layout
  if @user.site_theme == 'hometastic'
    'hometastic'
  else
    'agent'
  end
end

答案 1 :(得分:0)

我认为“布局”的中间件未正确加载

要在rails应用程序中加载“布局”中间件, 将以下行写入应用程序控制器

include ::ActionView::Layouts

答案 2 :(得分:0)

只需在应用程序控制器中添加以下代码行:

包括 ActionView::Layouts