How to store some data in session

Hi everyone,

I wanted to know how do i save some data in session and later retrieve
that.
I am new to rails and just couldn’t find any help regarding this.

Thank you

Qasim Ali wrote:

Hi everyone,

I wanted to know how do i save some data in session and later retrieve
that.
I am new to rails and just couldn’t find any help regarding this.

Thank you

I’d suggest you make a new table to store the session ‘object’ (like,
say, baskets if its a shopping basket).

Then you just do

session[:my_basket_id] = @basket.id

You are strongly advised against just doing session[:basket] =
@basket, and storing just the id in the session instead.

Does this make sense ?

Alan

Alan F. wrote:

Qasim Ali wrote:

Hi everyone,

I wanted to know how do i save some data in session and later retrieve
that.
I am new to rails and just couldn’t find any help regarding this.

Thank you

I’d suggest you make a new table to store the session ‘object’ (like,
say, baskets if its a shopping basket).

Then you just do

session[:my_basket_id] = @basket.id

You are strongly advised against just doing session[:basket] =
@basket, and storing just the id in the session instead.

Does this make sense ?

Alan

Thank you Alan for your quick response. But why should we go for the
database solution instead of simply utilizing the session variable, is
there some specific reason for not using the session[:basket] = …

Thanks

Qasim Ali wrote:

Alan F. wrote:

Qasim Ali wrote:

Hi everyone,

I wanted to know how do i save some data in session and later retrieve
that.
I am new to rails and just couldn’t find any help regarding this.

Thank you

I’d suggest you make a new table to store the session ‘object’ (like,
say, baskets if its a shopping basket).

Then you just do

session[:my_basket_id] = @basket.id

You are strongly advised against just doing session[:basket] =
@basket, and storing just the id in the session instead.

Does this make sense ?

Alan

Thank you Alan for your quick response. But why should we go for the
database solution instead of simply utilizing the session variable, is
there some specific reason for not using the session[:basket] = …

Thanks

See here: http://wiki.rubyonrails.org/rails/pages/sessions

Mostly to do with objects being stale, some security issues, and the
sheer size of the sessions.

A.