So I define current_user in User model as a global variable:
cattr_accessor :current_user
I application controller, I define who current user is:
def current_user
@current_user = User.find(1)
return @current_user if defined?(@current_user)
end
It does appear that the method overrides the one in model, assuming the
one in model is a getter/setter.
Nevertheless, when I make a reference to it in one of my views, I get
undefined error method. Any idea?
At the top of your controller, you’ll want to add
helper_method :current_user
But I don’t understand what the ‘cattr_accessor :current_user’ in your user model accomplishes; where or how will you use that? You aren’t using it in the controller. What I’m saying is, you don’t need that, and probably don’t want it.