Link_to with all properties of a model

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

@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

hash manipulation could go for :

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}

:slight_smile:

ciao

s