[Rails] Re: A Good Tutorial on Params and Variables

Ted Battreall
2006-04-30T06:10:00Z

One more question. You said "Note, if you are embedding a
''class''
into sessions, you also need to specify a ''model'' so other
controllers
know how to process the chunk of data specified in the session".

I think this may be the root of my session problems.  I wanted to store
the user information after login, so I can use it throughout my
application.

I used the syntax you described:
session[:user] ||= @user

This works fine within the Controller it was assigned it, but it has a
Nil value when I try to reference it in other Controllers. You mentioned
that I need to specify a model. What is the syntax for doing this?

Specifically here is the code:

class UserController < ApplicationController
  model   :user
  layout  ''scaffold''

  def login
    return if generate_blank
    @user = User.new(@params[''user''])
    if session[''user''] =
User.authenticate(@params[''user''][''login''],
@params[''user''][''password''])
      flash[''notice''] = l(:user_login_succeeded)
      session[:user] ||= @user
...

class UserNotify < ActionMailer::Base
  def invite(person)
    @recipients = person.email
    @from = @session[:user].email
...