# Always passing the same params

**URL:** <https://www.ruby-forum.com/t/always-passing-the-same-params/90650>\
**Category:** Rails\
**Created:** [March 30, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/always-passing-the-same-params/90650 "2007-03-30T18:18:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 30, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/always-passing-the-same-params/90650/1 "2007-03-30T18:18:02Z")

</div>

Hi, I’m building an application that have many types of search requests  
like simple search, search within results, sort results, sort the  
displaying fields, show/hide fields…  
To do this I’m using several params[:X] variables which I’m passing all  
the time from one method to another.  
I’m passing those params with GET (through the URL) wich I don’t like at  
all. So:

1. which would be a better way to do it insteaf of GET?. And

2. is there an automated way to pass all the params (or the ones I’d  
choose) from one request to another?

Thanks.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 30, 2007, 7:18pm UTC](https://www.ruby-forum.com/t/always-passing-the-same-params/90650/2 "2007-03-30T19:18:29Z")

</div>

Yes,  
You can store all those variables in a session variable. Sessions  
allow you to store variables between requests, and give you ‘state’.

In your controllers, you can assign a session variable:

def index  
session[:my\_first\_setting] = nil  
end

def change\_setting  
session[:my\_first\_setting] = params[:setting1]  
end

def search  
order = session[:my\_first\_setting] ? “updated\_at DESC” : “updated\_at  
ASC”  
@results = Items.find(:all, :order =\> order)  
end

You can store almost any data object in a session hash.

On Mar 30, 12:18 pm, Fernando P. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 30, 2007, 7:35pm UTC](https://www.ruby-forum.com/t/always-passing-the-same-params/90650/3 "2007-03-30T19:35:16Z")

</div>

First, thx for your answer.

John T. wrote:

> You can store all those variables in a session variable. Sessions  
> allow you to store variables between requests, and give you ‘state’.

Yes, sessions give you ‘state’ which is the best approach for  
applications like a shopping cart. However, session is not good for me  
(I think) because the users of my application may use more than one  
navigation window and I don’t want ‘state’ between them, wich will  
happen if I use sessions.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [March 30, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/always-passing-the-same-params/90650/4 "2007-03-30T22:35:54Z")

</div>

You can use flash (ie. flash[:my\_variable] = my\_data) to pass  
information from one action to the next. Be careful how you use it. I  
have ran into some problems passing variables back to the same action  
using different request methods.

On Mar 30, 10:35 am, Fernando P. \<rails-mailing-l…@andreas-
