Rails 2.0 and link_to_remote :with

I’m moving an old app to Rails 2.0 and other than fixing some routes Ajax calls with link_to_remote and the :with parameter was the only thing that gave me some trouble. In the old version I was grabbing the current value of a drop down list with Prototype and passing it along using :with like this

<%= link_to_remote image_tag('cms/add_16.gif', :id => "color_add"),
      :url => { :controller => "colors", :action => "new_ajax",
      :id => @product.id },
      :with => "{ color_id: $F('color_id') }"
%>

But in Rails 2.0 the parameter wouldn’t go along for the ride, it seemed that the new authenticity_token that gets sent with Ajax calls was messing things up. Here’s the fix

<%= link_to_remote image_tag('cms/add_16.gif', :id => "color_add"),
      :url => { :controller => "colors", :action => "new_ajax",
      :id => @product.id },
      :with => "'color_id='+$F('color_id')"
%>

I freely admit JavaScript/Ajax is my weakest language so if I was doing it wrong the entire time let me know :)

3 Comments

  1. Posted May 9, 2008 at 2:19 pm | Permalink

    thanks! I am new to rails in general and had no clue how to attach a dom node value to my ajax requests. This is kind of a cornerstone of what I like to do.
    Now I know!

  2. webmaster
    Posted March 17, 2010 at 10:31 am | Permalink

    that’s work for me! thanks!

    “0″, :align=>”absmiddle”), :update => “resultado”, :url => { :action => “actualiza_lineas” }, :with => “{ filtro_lineas: $F(’filtro_lineas’) }” %>

    a question… what’s global var $F ?? the form id, name or so??

  3. Knusbaerli
    Posted September 9, 2010 at 6:29 am | Permalink

    $F is a protoype helper function to query the value of the form-input element given as id in the parameters of the $F function.

Post a Comment

Your email is never shared. Required fields are marked *

*
*

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word