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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
1c357f90ccd53e1d0e12e9dd08a4940c?d=identicon&s=25 travis michel (Guest)
on 2006-04-11 07: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
private
  def set_user
    @user = session[:user] ||= User.find_by_username('nobody')
  end


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