I need to pull user preferences on every page load of every controller
and action in my app. I do this like so:
@user = User.find(@session[‘user’].id)
@prefs = @user.prefs
And it works fine in the action of one of my controllers, but I
certainly don’t want to plunk it in every instance. Where do you
normally put something like this? I tried putting it in the application
controller (application.rb), but it gives me the nil object error.
On 31/03/06, Ryan W. [email protected] wrote:
I need to pull user preferences on every page load of every controller
and action in my app. I do this like so:
@user = User.find(@session[‘user’].id)
@prefs = @user.prefs
And it works fine in the action of one of my controllers, but I
certainly don’t want to plunk it in every instance. Where do you
normally put something like this? I tried putting it in the application
controller (application.rb), but it gives me the nil object error.
I’d suggest using it as a :before_filter in the application
controller, but you’ll want to check that the @user object exists
before using it, of course.
David