Can't get sessions to work. Getting 500 Internal Server Error

Hi,
I’ve been fiddling around with rails for a while now. Following
books, tutorials etc.
But as soon as I tried to use sessions in my application, eg. by
calling session[:user] = ‘something’
All I get is “500 Internal Server Error”

(Both in webrick and mongrel) on OS X Leopard using ruby 1.8.6
I’ve also tried upgrading from rails 2.0.2 to 2.1.0

Log:

=================================================================================
/!\ FAILSAFE /!\ Sat Aug 02 21:17:45 +0200 2008
Status: 500 Internal Server Error
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]=
/Users/thomas/Ruby/kattene/app/controllers/application.rb:6:in
initialize' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ base.rb:388:innew’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/
base.rb:388:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:171:inhandle_request’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/
dispatcher.rb:115:in dispatch' /Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:126:indispatch_cgi’
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/
dispatcher.rb:9:in dispatch' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ rails.rb:76:inprocess’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/…/lib/mongrel/
rails.rb:74:in synchronize' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/../lib/mongrel/ rails.rb:74:inprocess’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in
process_client' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:ineach’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in
process_client' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:inrun’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
initialize' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:innew’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in
run' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:ininitialize’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in
new' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:inrun’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/
configurator.rb:282:in run' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/ configurator.rb:281:ineach’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/
configurator.rb:281:in run' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:128:inrun’
/Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/lib/mongrel/command.rb:
212:in run' /Library/Ruby/Gems/1.8/gems/mongrel-1.1.5/bin/mongrel_rails:281 /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:489:inload’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:489:in load' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:innew_constants_in’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:489:in load' /Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/servers/ mongrel.rb:64 /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:ingem_original_require’
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in require' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/
dependencies.rb:342:in new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:inrequire’
/Library/Ruby/Gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:in
gem_original_require' /Library/Ruby/Site/1.8/rubygems/custom_require.rb:27:inrequire’
script/server:3

=================================================================================

From ApplicationController:

def initialize
session[:test] = ‘something’
end

It shouldn’t be anything wrong with this as far as I know.

Any response would be highly appreciated.

Thanks,
Thomas Pedersen

On 2 Aug 2008, at 20:37, TyR wrote:

From ApplicationController:

def initialize
session[:test] = ‘something’
end

It shouldn’t be anything wrong with this as far as I know.

I’m afraid there is something wrong with that: you’re overriding
ActionController’s initialize one with your own, with doesn’t call the
super class implementation, probably doesn’t have the same signature,
and at that point the session isn’t setup.
What are you trying to do?

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs