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:
我有一个表单,旁边有一个带复选框的人员列表。然后我有一个submit_to_remote,它会将检查过的人员传递给控制器进行处理。它目前通过以下格式检查人员:
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.
其中checkbox_value是person_id。这来自使用参数的原型:Form.serialize(this.form)来构建参数。
However, since the submit_to_remote
button is a "disable" button I would like an action that looks like:
但是,由于submit_to_remote按钮是“禁用”按钮,我想要一个看起来像这样的动作:
people/disable/person_id1,person_id2,person_id3
This would disable those people, and I think the syntax is more API friendly.
这会禁用那些人,我认为语法更加API友好。
How do I change the parameters before the Ajax Updater submits using options in the submit_to_remote
helper?
如何在Ajax Updater使用submit_to_remote助手中的选项提交之前更改参数?
1 个解决方案
#1
Use Form.serialize(true) to get a hash with parameter names as keys.
使用Form.serialize(true)获取带参数名称作为键的哈希。
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.
然后,Ajax.Updated将接受修改后的哈希作为参数。
Oh, and if you want another target for this form, just specify it! It's teh first parameter, if I recall correctly.
哦,如果你想要这个表单的另一个目标,只需指定它!如果我没记错的话,这是第一个参数。
#1
Use Form.serialize(true) to get a hash with parameter names as keys.
使用Form.serialize(true)获取带参数名称作为键的哈希。
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.
然后,Ajax.Updated将接受修改后的哈希作为参数。
Oh, and if you want another target for this form, just specify it! It's teh first parameter, if I recall correctly.
哦,如果你想要这个表单的另一个目标,只需指定它!如果我没记错的话,这是第一个参数。