# Problem with sessions

**URL:** <https://www.ruby-forum.com/t/problem-with-sessions/125949>\
**Category:** Rails\
**Created:** [January 14, 2008, 3:33am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949 "2008-01-14T03:33:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 3:33am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/1 "2008-01-14T03:33:39Z")

</div>

Hi,

Does anyone know is it possible to have more than one sessions in a web  
application? If it is possible, can someone please tell me how can I  
acheive this?

Thanks  
fries 88

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 4:03am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/2 "2008-01-14T04:03:27Z")

</div>

Why would you want to do this?

On Jan 14, 2008 1:03 PM, fries 88 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 4:18am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/3 "2008-01-14T04:18:24Z")

</div>

Ryan B. wrote:

> Why would you want to do this?
> 
> On Jan 14, 2008 1:03 PM, fries 88 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> –  
> Ryan B.  
> [http://www.frozenplague.net](http://www.frozenplague.net)  
> Feel free to add me to MSN and/or GTalk as this email.

I kept counters in the session. Then I assigned counters to my page so  
that when I first enter the page, I will be able to save and the  
subsequent time I enter the same page I will be able to edit the data I  
saved previously. I have to do this for many other pages too. So I was  
thinking of having one session for a page. But I am not sure if it is  
right or possible.

controller:

def find\_count  
session[:count] ||= 0  
session[:count] += 1

```
if session[:count] == 1
  redirect_to :action => 'prod_desc'
else
  redirect_to :action => 'update_prod_desc'

  end
end

```

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 4:36am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/4 "2008-01-14T04:36:46Z")

</div>

I’m not sure what you’re trying to do but can’t you do:

session[:count]  
and then  
session[:othercount]

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 4:47am UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/5 "2008-01-14T04:47:18Z")

</div>

I dont think this is the right way to go about it.

You should have a link to create the data, and then another link to  
edit.  
You can decide which one shows by checking to see if the data exists  
before  
doing it.

## It sounds like you’re over-complicating something.

Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![fries88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fries88](https://www.ruby-forum.com/u/fries88)\
**Post date:** [January 14, 2008, 1:48pm UTC](https://www.ruby-forum.com/t/problem-with-sessions/125949/6 "2008-01-14T13:48:46Z")

</div>

On Jan 13, 2008, at 9:18 PM, fries 88 wrote:

> ```
> end
> 
> ```
> 
> –

One thing you can do is reference each page in the session.  
Something like

session[:page\_name][:counter]

If you want to automate it completely, you can even do

session[controller\_name][action\_name][:counter]

though I would probably convert controller\_name and action\_name to  
symbols with

session[controller\_name.to\_sym][action\_name.to\_sym][:counter]

On the other hand, if you only want to do manually, you can use a  
before filter to set a variable that you then use as the key into the  
session hash.

Having said that, Ryan might be onto something. You might want to  
step back and re-evaluate your requirements to see if you are  
overcomplicating some process.

Peace,  
Phillip
