views:

666

answers:

1

Hi. I'm using the :overwrite_params option in link_to helper. But I have problems overwriting nested parameters values. Here some code:

With:

link_to book_item.editorial, :overwrite_params  => {:filter => {[editorials.id] => book_item.editorial.id.to_s}}

The complete params[:filter] value is replaced (ie. I lost params[:filter][:author] value)

If I use:

link_to book_item.editorial, :overwrite_params  => {'filter[editorials.id]' => book_item.editorial.id.to_s}

I don't lost values, but if params[:filter][:editorials] exists in the url, another params[:filter][:editorials] is attached, so I don't get any overwrite.

Any help?

Thanks in advance.

+1  A: 

Giving a looong shot here.
Can you try this:

link_to book_item.editorial, :overwrite_params  => { :filter => params[:filter].merge({[editorials.id] => book_item.editorial.id.to_s}) }

Then you'd probably need to initialize params[:filter] somewhere, to make sure you don't run nil.merge()

Just do

params[:filter] ||= {}

somewhere in your code.

Once again, that's probably not the best solution.
Hopefully it will help you figure something out or keep moving until someone gives a better answer :)

Carlos Lima