Tony
Tony

Reputation: 19161

How do I alter request parameters before posting XHR action in Ruby On Rails?

I have a form with a list of people with check boxes next to them. Then I have a submit_to_remote which will pass the checked people into the controller for processing. It currently passes checked people in the form:

checkbox_name => checkbox_value

where checkbox_value is the person_id. This comes from prototype using parameters:Form.serialize(this.form) to build the parameters.

However, since the submit_to_remote button is a "disable" button I would like an action that looks like:

people/disable/person_id1,person_id2,person_id3 

This would disable those people, and I think the syntax is more API friendly.

How do I change the parameters before the Ajax Updater submits using options in the submit_to_remote helper?

Upvotes: 0

Views: 701

Answers (1)

alamar
alamar

Reputation: 19343

Use Form.serialize(true) to get a hash with parameter names as keys.

You can do whatever you want to that hash, includeing deleting inputs, altering their values, filtering them and so on.

Ajax.Updated then will accept that modified hash as a parameter.

Oh, and if you want another target for this form, just specify it! It's teh first parameter, if I recall correctly.

Upvotes: 1

Related Questions