# Storing information in session in rails - How to?

**URL:** <https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418>\
**Category:** Rails\
**Created:** [April 1, 2009, 8:40am UTC](https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418 "2009-04-01T08:40:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2009, 8:40am UTC](https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418/1 "2009-04-01T08:40:06Z")

</div>

Hi,

I am a rails newbie and i need to store some info. in the session, so  
that i can use it in any controllers when needed.

## in config/enviroment.rb, i have,

## config.action\_controller.session = { :session\_key =\> ‘\_xxx\_ui\_session’, :secret =\> ‘70ec05c894289359662252cdfd64e359822861bfd85626d0cc0699b4cef6ab409861e5dce5c9359918cedf4f58fa6fb73e2697ddb32d5ef4bd 4076cf31c1af8d’ }

## In application.rb, i have,

class ApplicationController \< ActionController::Base  
require ‘xmlrpc\_server’

@hostname = “127.0.0.1”  
@port = 8080  
@server = ServerProxy.new(@hostname, @port)

session[:server] = @server ===\> i get the error for this line

## end

But i keep on getting the error  
Symbol as array index

Am i going wrong anywhere, please suggest

Thanks and Regards,  
Vimal Das

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2009, 10:35am UTC](https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418/2 "2009-04-01T10:35:18Z")

</div>

On Apr 1, 7:39 am, vimal [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> end
> 
> * * *
> 
> But i keep on getting the error  
> Symbol as array index
> 
> Am i going wrong anywhere, please suggest

Yes - the session doesn’t exist at that point (this code is run when  
the application is started, not when a request is being processed  
(which is the only time a session is available).

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2009, 11:29am UTC](https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418/3 "2009-04-01T11:29:59Z")

</div>

config.action\_controller.session = {  
:session\_key =\> ‘\_xxx\_ui\_session’,  
:secret =\>  
‘70ec05c894289359662252cdfd64e359822861bfd85626d0cc0699b4cef6ab409861e5dce5c9359918cedf4f58fa6fb73e2697ddb32d5ef4bd  
4076cf31c1af8d’  
}  
this code will work before version 2.3.2 but in rails 2.3.3 it is  
changed to  
config.action\_controller.session = {  
:key =\> ‘\_xxx\_ui\_session’,  
:secret =\>  
‘70ec05c894289359662252cdfd64e359822861bfd85626d0cc0699b4cef6ab409861e5dce5c9359918cedf4f58fa6fb73e2697ddb32d5ef4bd  
4076cf31c1af8d’  
}

On Wed, Apr 1, 2009 at 2:04 PM, Frederick C.  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 1, 2009, 12:03pm UTC](https://www.ruby-forum.com/t/storing-information-in-session-in-rails-how-to/164418/4 "2009-04-01T12:03:29Z")

</div>

Thanks for your suggestions.

But i need some additional suggestions, as i am a newbie in both rails  
and xmlrpc  
I have an xmlrpc client in ruby stored inside the controllers  
directory  
and guessing how to get the connection and store it in a session.

All i want to do is,

1. Establish a connection only once and store the connection variable  
in session like --\> session[:server\_conn] = @server\_conn
2. Request a cookie after authentication ad store that in session like  
–\> session[:cookie] = @cookie

So that i can access the session variables in other controllers  
too…

Regards,  
Vimal Das
