在Ruby On Rails中发布XHR操作之前,如何更改请求参数? [英] How do I alter request parameters before posting XHR action in Ruby On Rails?

查看:59
本文介绍了在Ruby On Rails中发布XHR操作之前,如何更改请求参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,里面有一个人的名单,旁边有复选框.然后,我有一个 submit_to_remote ,它将检查的人员传递到控制器中进行处理.当前,它以以下形式通过检查人员:

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

其中 checkbox_value person_id .这来自使用 parameters:Form.serialize(this.form)的原型建立参数.

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

但是,由于 submit_to_remote 按钮是禁用"按钮,因此我希望执行以下操作:

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 

这将禁用这些人,并且我认为语法更加API友好.

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

如何使用 submit_to_remote 帮助器中的选项在Ajax Updater提交之前更改参数?

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

推荐答案

使用Form.serialize(true)获取以参数名称作为键的哈希.

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然后将接受修改后的哈希作为参数.

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.

这篇关于在Ruby On Rails中发布XHR操作之前,如何更改请求参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆