xxx
xxx

Reputation: 516

Undefined method `layout' for

I have method in my class Site::BaseController < ApplicationController

before_filter :check_layout

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

When i do only

layout 'agent'  

it works perfectly

but when i added before_filter i have got undefined method layout for

Rails 3.2.16

Any suggestions? error screen

Upvotes: 5

Views: 3498

Answers (3)

Abhishek Tanwar
Abhishek Tanwar

Reputation: 21

just add the following lines of code in application controller:

include ActionView::Layouts

Upvotes: 1

Amol Udage
Amol Udage

Reputation: 3075

I think middleware for 'layout' is not loaded properly

To load "layout" middleware in your rails application, Write below line to your application controller

include ::ActionView::Layouts

Upvotes: 0

j-dexx
j-dexx

Reputation: 10406

You can use a symbol which Rails will use to evaluate it when a request is processed. Guides

layout :themed_layout

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

Upvotes: 2

Related Questions