Using a method defined in appliciaton_controller.rb in application_controller.rb
Posted
by
E.E.33
on Stack Overflow
See other posts from Stack Overflow
or by E.E.33
Published on 2012-12-13T05:00:39Z
Indexed on
2012/12/13
5:03 UTC
Read the original article
Hit count: 124
ruby-on-rails
|ruby
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
© Stack Overflow or respective owner