Rails:link_to_remote原型帮助器:带选项

时间:2010-03-31 11:26:55

标签: ruby-on-rails

我正在尝试使用Prototype获取下拉列表的当前值并使用以下方式传递:使用此类

<%= link_to_remote "today", :update => "choices",
    :url => { :action => "check_availability" } , 
    :with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'",
    :loading => "spinner.show(); $('submit').disable();",
    :complete   => "spinner.hide(); $('submit').enable();" %>

但是,这没有按预期工作。我无法访问控制器中的参数,因为link_to_remote助手正在发送如下参数:

Parameters: {"succ"=>"function () {\n    return this + 1;\n}", "action"=>"check_availability", "round"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "ceil"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "floor"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "times"=>"function (iterator, context) {\n    $R(0, this, true).each(iterator, context);\n    return this;\n}", "toPaddedString"=>"function (length, radix) {\n    var string = this.toString(radix || 10);\n    return \"0\".times(length - string.length) + string;\n}", "toColorPart"=>"function () {\n    return this.toPaddedString(2, 16);\n}", "abs"=>"function () {\n    return __method.apply(null, [this].concat($A(arguments)));\n}", "controller"=>"main"}

我哪里错了?有更好的方法吗?

3 个答案:

答案 0 :(得分:1)

试试这个

<%= link_to_remote "today", :update => "choices",
    :url => { :action => "check_availability" } , 
    :with => "'practitioner='+$F('practitioner')+&'clinic='+$F('clinic')+&'when=today'",
    :loading => "spinner.show(); $('submit').disable();",
    :complete   => "spinner.hide(); $('submit').enable();" %>

这是差异

:with => "'practitioner='+$F('practitioner')&'clinic='+$F('clinic')&'when=today'",

应该改为

:with => "'practitioner='+$F('practitioner')**+**&'clinic='+$F('clinic')**+**&'when=today'",

参考:http://firstruby.wordpress.com/2008/11/03/remote_function-or-link_to_remote-with-multiple-parameters-in-ruby-on-rails/

答案 1 :(得分:0)

谢谢你,Salil。

您建议的解决方案也存在一些问题(抛出Javascript语法错误)。我猜它有与我相同的报价问题,我无法弄清楚。但解决方案干净利落地解决了这个问题,并且运作顺利:

:with => "$H({ practitioner: $F('practitioner'), clinic: $F('clinic'), 
         when: 'today' }).toQueryString()"

参考:http://www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterious-parameter

答案 2 :(得分:0)

我建议这样做:

<%= link_to_remote "today", :update => "choices",
  :url => { :action => "check_availability" } , 
  :with => "'practitioner='+$('practitioner').value +'&clinic='+$('clinic').value+'&when=today'",
  :loading => "spinner.show(); $('submit').disable();",
  :complete   => "spinner.hide(); $('submit').enable();" %>