在form_remote_tag中如何用Form.serialize('test_form)替换paramaters Form.serialize(this)?

时间:2011-07-15 00:29:15

标签: ruby-on-rails forms prototypejs

使用form_remote_tag(options = {},& block)

form_remote_tag :html => { :action => url_for(:controller => "some", :action => "place") } 
Generates:
 <form action="/some/place" method="post" onsubmit="new Ajax.Request('',
{asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">

我想更改“新的Ajax.Request(...”代码,如Form.serialize(“test_form”)中的参数,以便生成的代码就像

 <form action="/some/place" method="post" onsubmit="new Ajax.Request('',
{asynchronous:true, evalScripts:true, parameters:Form.serialize(test_form)}); return false;">

有没有办法传递任何选项来改变它,还是有更好的方法来处理它?<​​/ p>

1 个答案:

答案 0 :(得分:0)

<% options = {:url => "/some/place", :with =>"Form.serialize('test_form')" }%>
<% form_remote_tag :html => { :onsubmit => #{remote_function(options)}; return false"} 

这可以达到目的,因为传递给html的选项会附加到远程函数调用中,返回false 会确保它超出rails生成的默认值。

以下是generatd的样本表格

 < form onsubmit="new Ajax.Request('/some/place', {asynchronous:true, evalScripts:true, parameters:Form.serialize('test_form') )}); return false; new Ajax.Request('',{asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;>