Where do I put the Current user query so as to not repeat per controller?

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-05-14T22:29:47Z Indexed on 2010/05/14 22:34 UTC
Read the original article Hit count: 209

I have a standard query that gets the current user object:

@user = User.find_by_email(session[:email])

but I'm putting it as the first line in every single controller action which is obviously not the best way to do this. What is the best way to refactor this?

Do I put this as a method in the Application controller (and if so, can you just show me a quick example)?

Do I put the entire @user object into the session (has about 50 columns and some sensitive ones like is_admin)?

Or is there another way to remove this kind of redundancy?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about best-practices