Forum: Ruby on Rails a user model in all controllers in 6 lines of code

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
travis michel (Guest)
on 2006-04-11 09:05
(Received via mailing list)
Well it took a bit of research, and making a fool out of myself; but I
found a way to get a user model from the session and have it
accessible in every controller and view in 6 lines of code.

In the ApplicationController write

model :user
before_filter :set_user
  def set_user
    @user = session[:user] ||= User.find_by_username('nobody')

I have redeemed myself (whoohoo!!)
This topic is locked and can not be replied to.