# Link\_to with all properties of a model

**URL:** <https://www.ruby-forum.com/t/link-to-with-all-properties-of-a-model/81528>\
**Category:** Rails\
**Created:** [January 9, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/link-to-with-all-properties-of-a-model/81528 "2007-01-09T18:03:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [January 9, 2007, 6:03pm UTC](https://www.ruby-forum.com/t/link-to-with-all-properties-of-a-model/81528/1 "2007-01-09T18:03:08Z")

</div>

Hi,

I am trying to create a link with all of the properties of a model as  
parameters. Is this possible in a generic way?

Say I have the model:

filter = Filter.new  
filter.page\_number = 2  
filter.page\_size = 10  
filter.query = ‘books’

I want to create a link link:

 

Thanks,  
GiantCranes

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [January 10, 2007, 1:28pm UTC](https://www.ruby-forum.com/t/link-to-with-all-properties-of-a-model/81528/2 "2007-01-10T13:28:42Z")

</div>

> @filter = Filter.new  
> @filter.page\_number = 2  
> @filter.page\_size = 10  
> @filter.query = ‘books’

– untested code. the idea is that @filter.attributes returns a hash  
like  
@filter.attributes = {:page\_number =\> 2, :page\_size =\> 10, :query =\>  
‘books’}

so, you should aim for something like:

link\_to “abc”, {:controller =\> ‘some’, :action =\> ‘action’,  
@filter.attributes }

\*\*((you may need to do some hash - manipulation, so you don’t get a hash  
in a hash (you want it all to be in one hash), but that’s the idea…

hth,

shai

---

<div class="post-metadata">

**Author:** ![giantcranes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ecd19e/32.png) [@giantcranes](https://www.ruby-forum.com/u/giantcranes)\
**Post date:** [January 10, 2007, 1:35pm UTC](https://www.ruby-forum.com/t/link-to-with-all-properties-of-a-model/81528/3 "2007-01-10T13:35:35Z")

</div>

hash manipulation could go for :

Hash#update  
[http://rubycentral.com/book/ref\_c\_hash.html#Hash.update](http://rubycentral.com/book/ref_c_hash.html#Hash.update)

something like:

n={:a =\> 1, :b =\> 2 }  
m={:c =\> 3}

n.update(m) # gives {:a =\> 1, :b =\> 2, :c =\> 3}

this way you can add the two hashes of {:controller =\> x,:action =\> y}  
and {:page\_number =\>2, :other =\> attributes}

🙂

ciao

s
