railstutorial.org has a suggestion which strikes me as a little odd.
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
end
The include SessionsHelper makes the methods available from ApplicationController, yes, but it makes them available in any view, as well. I understand that authentication/authorization is cross-cutting, but is this really the best place?
That seems to me to be potentially too broad of a scope. Putting code which implements, say, a before_filter which conditionally redirects (as the railstutorial.org example does) in a module which more commonly contains view helpers seems surprising.
Would functionality not strictly needed in views be better placed in ApplicationController or elsewhere?
Or am I just thinking too much about this?
Indeed, your feeling is correct.
I would implement this the other way around: add the functions
sign_inandcurrent_usertoApplicationController(or if you really want to: in a separate module defined inliband include it), and then make sure that thecurrent_usermethod is available in the view.In short:
Of course, if you have a lot of code to place into your
ApplicationControllerit can get messy. In that case I would create a filelib\session_management.rb:and inside your controller you can then just write: