Strange thing – I have Authentication module in lib/ like this:
module Authentication
protected
def current_user
User.find(1)
end
end
and in ApplicationController I’m including this module and all helpers, but method current_user is available in controllers, but not from views 🙁 How can I make this work?
If the method were defined directly in the controller, you’d have to make it available to views by calling
helper_method :method_name.With a module, you can do the same, but it’s a bit more tricky.
Ah, yes, if your module is meant to be strictly a helper module, you can do as Lichtamberg said. But then again, you could just name it
AuthenticationHelperand put it in theapp/helpersfolder.Although, by my own experience with authentication code, you will want to have it be available to both the controller and views. Because generally you’ll handle authorization in the controller. Helpers are exclusively available to the view. (I believe them to be originally intended as shorthands for complex html constructs.)