开发者

Rails: link_to_remote prototype helper with :with option

开发者 https://www.devze.com 2022-12-25 00:59 出处:网络
I am trying to grab the cur开发者_如何学Crent value of a drop down list with Prototype and passing it along using :with like this

I am trying to grab the cur开发者_如何学Crent value of a drop down list with Prototype and passing it along using :with like this

<%= 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();" %>

However, this is not working as expected. I am unable to access parameters in the controller as the link_to_remote helper is sending parameters like this:

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"}

Where am I going wrong? Is there a better way to do this?


Try this

<%= 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();" %>

Here is the difference

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

Should change to

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

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


Thank you, Salil.

The solution you suggested also have some problems (throwing Javascript syntax error). I guess it has the same quotes issue as mine, which I am unable to figure out. But the solution cleanly solves that problem and works smoothly:

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

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


I suggest to do like this:

<%= 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();" %>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号