# :params =\> params does not work :-(

**URL:** <https://www.ruby-forum.com/t/params-params-does-not-work/87862>\
**Category:** Rails\
**Created:** [March 6, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862 "2007-03-06T14:10:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/1 "2007-03-06T14:10:56Z")

</div>

Hello  
I’m applying some filter functionallity to my controller and would  
like to have pagination and params sendt without using sessions.  
My filter works and it is sent so I can use it like this:

params[:filter][:filter\_a]  
params[:filter][:filter\_b]  
and so on.

This works fine, but problem start when I use pagination and would  
like to send the params array to the next page.

So I do something like this:  
\<%= link\_to ‘Next’, { :page =\> @myObjects\_pages.current.next, :params  
=\> params } %\>

When I do this the link does not work. It seems it is changed from:  
[http://myhost/mycontroller;filter?filter[filter\_a]=X](http://myhost/mycontroller;filter?filter%5Bfilter_a%5D=X)  
to:  
[http://myhost/mycontroller;filter?page=2&filter=filter\_aX](http://myhost/mycontroller;filter?page=2&filter=filter_aX)

Any easy fixes here?

/Frode

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/2 "2007-03-06T16:54:34Z")

</div>

MartOn wrote:

> like to send the params array to the next page.  
> Any easy fixes here?
> 
> /Frode
> 
> >

Frode, why do not you try with:  
\<%= link\_to ‘Next’, { params.merge({:page =\>  
@myObjects\_pages.current.next}) } %\>

hope that helps…  
Bojan

–  
Bojan M.  
 → Ruby on Rails and Web D. Blog : [http://source.mihelac.org](http://source.mihelac.org)

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 6:41pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/3 "2007-03-06T18:41:01Z")

</div>

It is DRY’er, but it still does not work  
Still the %5B and the %5D and the = signs are gone…  
It seems it does not support multi dimension params array…

/Frode

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/4 "2007-03-06T19:19:07Z")

</div>

On Tue, 2007-03-06 at 05:07 -0800, MartOn wrote:

> like to send the params array to the next page.  
> Any easy fixes here?

* * *

I’m not sure that I would personally do this but…

params =\> @params

should probably work

–  
Craig W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 8:38pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/5 "2007-03-06T20:38:21Z")

</div>

Generates the same problem as mentioned in my first post.  
the params array holds all information, but I need to know how to  
konvert it correctly to :params.

/MartOn

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 8:52pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/6 "2007-03-06T20:52:22Z")

</div>

> So I do something like this:  
> \<%= link\_to ‘Next’, { :page =\> @myObjects\_pages.current.next, :params  
> =\> params } %\>
> 
> When I do this the link does not work. It seems it is changed from:  
> First you have to understand what’s going on here so you can fix it.  
> what you are doing with “link\_to” is generating a plain old anchor  
> (link) object in your html, so it’s going to be difficult to pass any  
> value other than a string (or something easy to convert to string).

One solution you can try is to serialize it with Marshal.dump(params)  
and then in the controller restore it with Marshal.restore. I’m not sure  
what kind of string you would obtain from Marshal and also not sure if  
link\_to is smart enough to escape the char sequence is necessary. If you  
find any issues about that, then you should Marshall then escape, and in  
the controller first unescape and then restore the object.

good luck!

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!

---

<div class="post-metadata">

**Author:** ![MartOn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@MartOn](https://www.ruby-forum.com/u/MartOn)\
**Post date:** [March 6, 2007, 9:01pm UTC](https://www.ruby-forum.com/t/params-params-does-not-work/87862/7 "2007-03-06T21:01:23Z")

</div>

Interesting… I will have a look at it.  
But I believe there must be some kind of functionality already in  
Rails.  
All this params management works inside the form\_for. I create for  
instance a text\_field ‘filter’, ‘filter\_a’  
and rails will send and handle the params handling for me… My problem  
is to send the same variables from a link and not from inside the  
form.  
PS! I’m using the Restful way and the form action uss GET instead of  
POST.

Ï have been thinking of changing the next link to a form button, but I  
would like to do it the Rails way…

Any1 knows about good examples/tutorials of filters in rails?

/Frode
