views:

342

answers:

1

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?

+1  A: 

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.

alamar
where do I do that? i am using the submit_to_remote helper with ruby on rails, and i would like to perform this action when the user presses submit but before the request is made
Tony
Well, you'll have to write some javascript in order this to work.Then you can put it into onsubmit, which you can specify in submit_to_remote's options if you want to.
alamar
Maybe I was not clear enough in the question. I understand how this works. I just don't know how to properly hook the code in ROR.
Tony
I'd recommend the "just code the damn javascript" pattern.You're trying to perform a tricky thing; Yes you are.So just use a tricky solution.Or else, do a dumb thing - just submit the form as it is and figure it out in controller. Nobody cares about your AJAX urls anyway.
alamar