I’ve got a variable called @current_user that I currently create in
each method of my controller. I’m thinking that I could reference it
at a higher level, and then only have it once in my code, but it’s not
clear to me where it should exist. I’ve got a bunch of objects that I
create in my models that are reused throughout my controllers, but
since this variable references session info, I can’t put it there.
Is there a simple solution to this (seems like there should be)?
Perhaps it should live in the application controller?
Thanks for your help.
I would recommend installing the restful_authentication plugin in a
new project and study how they do it. If you do this you will likely
drop your customized solution and simply use the plugin. It’s very
well done and would be a lot of work on your part to recreate. There
are some very easy instructions and it only takes a few minutes to
setup what you need for basic authentication. Then you can easily
extend your application to provided whatever authentication and
authorization you need. No need to reinvent the wheel here.