似乎无法为link_to_remote创建的Prototype参数设置url编码

时间:2010-12-09 10:39:04

标签: ruby-on-rails prototype

过去2个小时我一直在努力用rails的link_to_remote方法设置url编码。

我应该能够以“+4412323424”格式提交用户输入的手机号码。

目前,'+'没有被编码,因此控制器会收到一个空格而不是'+'。

我已经和Rails合作了一段时间了,但是我仍然有许多东西可以解决这个问题......

  

<%= link_to_remote“添加”,{:update => 'employees',:url => {:action => 'add_mobile'},:with => “'employee_mobile ='+ escape($('enter_mobile')。value)”},:class => 'btn_search'%>

这是生成的HTML:

  

< a onclick =“new Ajax.Updater('employees','/ sms / add_mobile',{asynchronous:true,evalScripts:true,parameters:'employee_mobile ='+ escape($('enter_mobile ')。value)});返回false;“ href =“#”class =“btn_search”>添加< / a >

我假设它必须是Ajax.Updater中的参数不正确?

有人能引导我朝正确的方向前进吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您的参数应该是对象的对象。

你希望它是这样的:

parameters: { employee_mobile: escape($('enter_mobile').value }

所以试试这个(我不熟悉rails语法,所以我在这里猜一点):

<%= link_to_remote "Add", {:update => 'employees', :url => {:action => 'add_mobile'}, 
:with => "'employee_mobile:' + escape($('enter_mobile').value)"}, 
:class => 'btn_search' %>