未定义的方法“布局”

xxx*_*xxx 5 layout ruby-on-rails ruby-on-rails-3 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
Run Code Online (Sandbox Code Playgroud)

当我只做

layout 'agent'  
Run Code Online (Sandbox Code Playgroud)

它工作得很好

但是当我添加时before_filter我得到了undefined method layout for

轨道 3.2.16

有什么建议么? 错误屏幕

j-d*_*exx 2

您可以使用一个符号,Rails 将在处理请求时使用该符号来评估它。指南

layout :themed_layout

def themed_layout
  if @user.site_theme == 'hometastic'
    'hometastic'
  else
    'agent'
  end
end
Run Code Online (Sandbox Code Playgroud)