# Wierd session behavious in development mode after switching

**URL:** <https://www.ruby-forum.com/t/wierd-session-behavious-in-development-mode-after-switching/82571>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/wierd-session-behavious-in-development-mode-after-switching/82571 "2007-01-19T16:31:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/wierd-session-behavious-in-development-mode-after-switching/82571/1 "2007-01-19T16:31:26Z")

</div>

class UserController \< ApplicationController  
def home  
# Following line throws error and session[:user] set by previous  
action login is gone here.  
$logme.info “Home session information: is #{session[:user].login}  
and #{session[:user].firstname}”  
redirect\_to\_stored\_or\_default :controller =\> “start”,:action =\>  
‘index’  
end

# trying to access also called from a Ajax request normally. If not,

they will be sent to “/user/home”.  
def login  
if session[:user]  
render :partial =\> ‘shared/error\_msg’, :object =\> “Invalid  
Request”, :layout =\> true  
return  
end

```
return if generate_blank

if @user = User.authenticate(params[:user][:login], 

```

params[:user][:password])  
@user.logged\_in\_at = Time.now

```
  session[:maps_cust_pref] = nil
  save_option = params[:save_option][:save_option].to_i

  generate_cookie_for_ticks

  save_pref if save_option == 1
  session[:user] = @user
  session[:user].save

  # printing session information works here, but as soon as we 

```

redirect\_to another page, all the session  
# information is lost  
$logme.info “From session information: is #{session[:user].login}  
and #{session[:user].firstname}”  
render :update do |page|  
page.redirect\_to(:controller =\> ‘user’,:action =\> ‘home’)  
end

```
else
  render :update do |page|
    page.replace_html('errordiv',:partial => 'error',
                      :object => "<p 

```

style=‘background:#d57068;margin:0px 200px 2px 0px; padding:2px 5px 2px  
5px; color:#ffffff;’\>Invalid Login ID or Password

")  
page.visual\_effect :highlight, ‘errordiv’  
end  
end  
end  
end

I am doing nothing special here and yet i wonder why this happens?

It was working alright on 1.1.6 although.

---

<div class="post-metadata">

**Author:** ![gnufied](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ea666f/32.png) [@gnufied](https://www.ruby-forum.com/u/gnufied)\
**Post date:** [September 25, 2007, 10:29pm UTC](https://www.ruby-forum.com/t/wierd-session-behavious-in-development-mode-after-switching/82571/2 "2007-09-25T22:29:25Z")

</div>

On Sat, 2007-01-13 at 05:08 +0530, Hemant K. wrote:

> ```
> render :partial => 'shared/error_msg', :object => "Invalid Request", :layout => true
> 
> page.redirect_to(:controller => 'user',:action => 'home')
> 
> ```
> 
> end
> 
> I am doing nothing special here and yet i wonder why this happens?
> 
> It was working alright on 1.1.6 although.

Well in case, anyone is looking for exact error its here:  
You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.login

RAILS\_ROOT: /home/gnufied/ubac\_webfront/config/…

Application Trace | Framework Trace | Full Trace  
#{RAILS\_ROOT}/app/controllers/user\_controller.rb:4:in `home' /usr/local/bin/mongrel_rails:18:in`load’  
/usr/local/bin/mongrel\_rails:18  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/base.rb:1092:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:1092:in`perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:632:in  
`call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:638:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:438:in  
`call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:637:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/benchmarking.rb:66:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/benchmarking.rb:66:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:427:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/base.rb:427:in  
`process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:624:in`process\_without\_session\_management\_support’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:330:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6.5848/lib/dispatcher.rb:41:in  
`dispatch' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:78:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:76:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:618:in  
`process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:617:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:617:in  
`process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in  
`initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in`new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in`initialize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in  
`new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:271:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:270:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:270:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/bin/mongrel_rails:127:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/command.rb:211:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/bin/mongrel_rails:243 #{RAILS_ROOT}/app/controllers/user_controller.rb:4:in`home’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/base.rb:1092:in  
`send' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:1092:in`perform\_action\_without\_filters’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:632:in  
`call_filter' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:638:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:438:in  
`call' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:637:in`call\_filter’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/filters.rb:619:in  
`perform_action_without_benchmark' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/benchmarking.rb:66:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/benchmarking.rb:66:in`perform\_action\_without\_rescue’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/rescue.rb:83:in  
`perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:427:in`send’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/base.rb:427:in  
`process_without_filters' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/filters.rb:624:in`process\_without\_session\_management\_support’  
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action\_controller/session\_management.rb:114:in  
`process' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.12.5.5848/lib/action_controller/base.rb:330:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/rails-1.1.6.5848/lib/dispatcher.rb:41:in  
`dispatch' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:78:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:76:in  
`synchronize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/rails.rb:76:in`process’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:618:in  
`process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:617:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:617:in  
`process_client' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in  
`initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in`new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:736:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in`initialize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in  
`new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel.rb:720:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:271:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:270:in`each’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/configurator.rb:270:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/bin/mongrel_rails:127:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/lib/mongrel/command.rb:211:in  
`run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-1.0/bin/mongrel_rails:243 /usr/local/bin/mongrel_rails:18:in`load’  
/usr/local/bin/mongrel\_rails:18  
Request  
Parameters: None

* * *

flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}
