Using a method defined in appliciaton_controller.rb in application_controller.rb
- by E.E.33
I want to change my layout based on whether or not the current user is an admin. So I made a simple method to check if current user is admin, I then call that method in application controller. I keep getting the following error:
undefined method `is_admin?' for ApplicationController:Class
My code looks like this:
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user, :is_admin?
if is_admin?
layout 'admin'
end
.....
protected
.....
def is_admin?
if current_user.user_role == 'admin'
return true
end
end
end
How should I be doing this?
Thanks