# Store session variable in a table

**URL:** <https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030>\
**Category:** Rails\
**Created:** [October 29, 2008, 10:24am UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030 "2008-10-29T10:24:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruby\_ishk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@ruby\_ishk](https://www.ruby-forum.com/u/ruby_ishk)\
**Post date:** [October 29, 2008, 10:24am UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030/1 "2008-10-29T10:24:40Z")

</div>

hi,can anyone tell me how a session variable can store in table,

---

<div class="post-metadata">

**Author:** ![ruby\_ishk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@ruby\_ishk](https://www.ruby-forum.com/u/ruby_ishk)\
**Post date:** [October 29, 2008, 12:26pm UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030/2 "2008-10-29T12:26:07Z")

</div>

On Oct 29, 4:19 pm, ruby\_ishk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi,can anyone tell me how a session variable can store in table,

Do you mean change from storing sessions in a cookie to storing in  
your database?  
Or do you mean something to do with using the session?

–  
Daniel B.

---

<div class="post-metadata">

**Author:** ![ruby\_ishk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@ruby\_ishk](https://www.ruby-forum.com/u/ruby_ishk)\
**Post date:** [October 29, 2008, 3:00pm UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030/3 "2008-10-29T15:00:00Z")

</div>

On Oct 30, 12:09 am, “Ishara G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> no, suppose that there’s a person who has logged in to a site  
> and when he fill a form so the data should be stored in a table  
> with his user id which has stored in his session. so how can  
> i store it.

You could access the session in the controller at the time the user  
submits.  
Depends on what your authentication system does.  
For instance it might be session[:user]. So you have to do something  
like  
user=User.find(session[:user])  
or  
User.exists?(session[:user])  
to verify the user id is valid.  
There may be helper methods which come with whatever plugin or system  
you’re using  
so you should check them out.

If you don’t have a system, there are quite a few.  
acts\_as\_authenticated, restful\_authentication to name 2.  
You’ll need to install one of them and read how to use it.

–  
Daniel B.

---

<div class="post-metadata">

**Author:** ![ruby\_ishk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@ruby\_ishk](https://www.ruby-forum.com/u/ruby_ishk)\
**Post date:** [October 30, 2008, 3:57am UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030/4 "2008-10-30T03:57:35Z")

</div>

thank you very much,now i can understand what should i do

---

<div class="post-metadata">

**Author:** ![ruby\_ishk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b5a626/32.png) [@ruby\_ishk](https://www.ruby-forum.com/u/ruby_ishk)\
**Post date:** [October 29, 2008, 2:09pm UTC](https://www.ruby-forum.com/t/store-session-variable-in-a-table/152030/5 "2008-10-29T14:09:58Z")

</div>

no, suppose that there’s a person who has logged in to a site  
and when he fill a form so the data should be stored in a table  
with his user id which has stored in his session. so how can  
i store it.
