How do I change request parameters before publishing an XHR action in Ruby on Rails?
I have a form with a list of people with checkboxes next to them. Then I have submit_to_remote
one that will pass the verified people to the controller for processing. He is currently undergoing verified people in the form:
checkbox_name => checkbox_value
where checkbox_value
- person_id
. This comes from prototype using parameters:Form.serialize(this.form)
to create parameters.
However, since the button submit_to_remote
is a "disable" button, I would like the action to look like this:
people/disable/person_id1,person_id2,person_id3
This will disable these people and I think the syntax is more API friendly.
How do I change the parameters before the Ajax Updater presents the parameters in the submit_to_remote
helper?
a source to share
Use Form.serialize (true) to get hash with parameter names as keys.
You can do whatever you want with a hash, including removing inputs, changing their values, filtering them, etc.
Ajax.Updated will then accept this modified hash as a parameter.
Oh, and if you want a different target for this form, just specify it! This is the first parameter if I remember correctly.
a source to share