# Search words and sessions

**URL:** <https://www.ruby-forum.com/t/search-words-and-sessions/173626>\
**Category:** Rails\
**Created:** [August 12, 2009, 9:24am UTC](https://www.ruby-forum.com/t/search-words-and-sessions/173626 "2009-08-12T09:24:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trausti\_Thor\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@Trausti\_Thor\_J](https://www.ruby-forum.com/u/Trausti_Thor_J)\
**Post date:** [August 12, 2009, 9:24am UTC](https://www.ruby-forum.com/t/search-words-and-sessions/173626/1 "2009-08-12T09:24:57Z")

</div>

Hi All,  
I am implementing a search for my blog. I have it as you can type in  
tags  
and words, and I keep them as session variables. I was just thinking if  
this was a good idea ?  
I saw on learning ruby on rails, that Ryan put such a search in a model  
and  
kept it in a database.

My site is hardly anything like twitter. So I would really like to hear  
what you have to say about this.

Trausti

---

<div class="post-metadata">

**Author:** ![Trausti\_Thor\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@Trausti\_Thor\_J](https://www.ruby-forum.com/u/Trausti_Thor_J)\
**Post date:** [August 12, 2009, 3:15pm UTC](https://www.ruby-forum.com/t/search-words-and-sessions/173626/2 "2009-08-12T15:15:36Z")

</div>

This may depend on what you want to do with those keywords:

1. Nothing:  
When why keep them at all? Run the search and forget them  
Or redisplay in the searchbox for next search, for that you can  
still get them from the params at this stage.

2. Keep the actual search for redisplay next time the user comes back  
You could keep them in the session, but would lose them if the user  
logs out.

3. Run statistics what users are searching  
Then you must keep them in the database

So I think there is not that much use in keeping them in the session.  
Keeping them in the database makes sense if you store every single  
search.

---

<div class="post-metadata">

**Author:** ![Trausti\_Thor\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/5daacb/32.png) [@Trausti\_Thor\_J](https://www.ruby-forum.com/u/Trausti_Thor_J)\
**Post date:** [August 12, 2009, 3:24pm UTC](https://www.ruby-forum.com/t/search-words-and-sessions/173626/3 "2009-08-12T15:24:58Z")

</div>

My idea is that as soon as the user leaves the website it should go  
away.  
No need to keep the query around.  
This just ends up in an array and will be run with :conditions on the  
query.

Trausti

On Wed, Aug 12, 2009 at 3:07 PM, Thorsten MÃ¼ller \<
