1

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 Answer 1

1

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 :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.