# How to generate parameters similar to a form

**URL:** <https://www.ruby-forum.com/t/how-to-generate-parameters-similar-to-a-form/182794>\
**Category:** Rails\
**Created:** [February 2, 2010, 10:27pm UTC](https://www.ruby-forum.com/t/how-to-generate-parameters-similar-to-a-form/182794 "2010-02-02T22:27:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [February 2, 2010, 10:27pm UTC](https://www.ruby-forum.com/t/how-to-generate-parameters-similar-to-a-form/182794/1 "2010-02-02T22:27:17Z")

</div>

hi guys,

i have a search form set up which points to my search controller.  
When I hit “submit” in the form, it activates the perform\_search  
method in my search controller.  
It works ok.

A typical GET request that is performed would look like this:

[http://my-test-box.local:3000/search?search[category\_id\_equals]=8&search[sub\_category\_id\_equals]=&](http://my-test-box.local:3000/search?search%5Bcategory_id_equals%5D=8&search%5Bsub_category_id_equals%5D=&)  
search[location\_like]=&search[new\_equals]=0&search[title\_like]  
=&commit=Search

Now, I would like to make a “hot list” in my index page which is  
basically links to “hot” items.

I am using the link\_to helper but i can’t seem to generate parameters  
similar to what it is like from a form.  
My perform\_search method has been coded to take search parameters  
strictly from “params[:search]”.

In short, I need to be able to generate a url with parameters that  
start with “[search]” followed by the attribute name and query value.

Something like:  
[http://my-test-box.local:3000/search?search[item\_id\_equals]=8](http://my-test-box.local:3000/search?search%5Bitem_id_equals%5D=8)  
.

How do I go about doing that?

thanks 🙂

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [February 2, 2010, 11:17pm UTC](https://www.ruby-forum.com/t/how-to-generate-parameters-similar-to-a-form/182794/2 "2010-02-02T23:17:03Z")

</div>

> search[category\_id\_equals]=8&search[sub\_category\_id\_equals]=&
> 
> In short, I need to be able to generate a url with parameters that  
> start with “[search]” followed by the attribute name and query value.
> 
> Something like: [http://my-test-box.local:3000/search](http://my-test-box.local:3000/search)?  
> search[item\_id\_equals]=8  
> .
> 
> How do I go about doing that?

When I do this in my view…

\<%= link\_to ‘test’, root\_path(:search =\> {:one =\> 1, :two =\> 2}) %\>

I get this in my development.log…

Processing HomeController#index (for 127.0.0.1 at 2010-02-02 14:14:42)  
[GET]  
Parameters: {“search”=\>{“two”=\>“2”, “one”=\>“1”}, “action”=\>“index”,  
“controller”=\>“home”}

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [February 2, 2010, 11:38pm UTC](https://www.ruby-forum.com/t/how-to-generate-parameters-similar-to-a-form/182794/3 "2010-02-02T23:38:43Z")

</div>

hello, Philip,  
Yes, it worked like a charm and it makes sense!

\<%= link\_to ‘test’, root\_path(:search =\> {:one =\> 1, :two =\> 2}) %\>

Perfect! thank you 🙂

Call closed 🙂
