是否可以在remote_form_for中使用:with选项?
它适用于link_to_remote,api文档似乎表明:with应该使用任何remote_方法。
这是我正在使用的代码,并输出它生成:
= link_to_remote 'ARGH', {:url => {:action => 'load_item', :id => @policy.id} , :with => "'elephant=mouse'"}
<a href="#" onclick="new Ajax.Request('http://localhost:3000/quote_edit/load_item/5', {asynchronous:true, evalScripts:true, parameters:'elephant=mouse' + '&authenticity_token=' + encodeURIComponent('o6whEDZLuq1b1NsuZXIlNjc3iudZNC8jU+ZxgUDXFUk=')}); return false;">arg</a>
= remote_form_for :policy, @policy, :url => {:action => 'load_item', :id => @policy.id} , :with => "'elephant=mouse'" do |f|
<form action="http://localhost:3000/quote_edit/load_item/5" method="post" onsubmit="new Ajax.Request('http://localhost:3000/quote_edit/load_item/5', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;">
有谁知道如何让remote_form_for选择此选项?
或者它是否被remote_form_for忽略,因为它需要使用parameters:Form.serialize(this)
从当前表单中获取值?
干杯 Dave Smylie
答案 0 :(得分:3)
当我想使用javascript来计算网址的ID时,我遇到了同样的问题。
研究了源代码并确定远程表单和提交似乎不允许:with语句工作。
我使用表单上名为overridden_id的隐藏字段来解决这个问题。然后在:before选项中,我添加了javascript来设置隐藏字段值。
在控制器内部,我将“params [:overriden_id] || parmam [:id]”添加到我的Find中,以覆盖传递给url的默认ID。