EDIT: See below unanswered part II.
(ANSWERED) I. Appending URLS
I am trying to stack parameters in my view by using basic parameter guidelines:
users_path(:a => 'test')
The above would return: ?a=test
However, I want to be able to consecutively click:
users_path(:b => 'goat')
and have it return ?a=test&b=goat
Any suggestions on how to stack/append these URL params?
(NOT ANSWERED) II. Removing parameters
If I want to add a [x]
link next to a parameter setting, how could I then remove its respective parameter?
(ANSWERED) III. Removing page
Parameter
I would like to remove the page
parameter when a user selects a parameter choice. Is there a way to do this? It's clear that if I select 'Sports' as a parameter category, pagination shouldn't remain on page, 26, for example.
If you want to append the current parameters, you could try this:
users_path(params.merge(:b => 'goat'))
You may want to write a helper method that does this for you:
def merged_with_current_params(additional)
params.merge(additional)
end
As to the second part of your question, you probably want to expand the incoming params
into a series of checkboxes with the names and values set appropriately. Disabling the checkbox and submitting the form would have the effect of removing that param from the request.
To remove :page
parameter, add this to your helper instead:
params.except(:page).merge(additional)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With