Vixiom Axioms

January 18, 2008

Rails 2.0 and link_to_remote :with

Filed under: Ajax, JavaScript, Ruby, Ruby on Rails Alastair @ 11:22 am

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 :)

Digg! submit Rails 2.0 and link_to_remote :with to stumbleupon.com submit Rails 2.0 and link_to_remote :with to del.icio.us submit Rails 2.0 and link_to_remote :with to reddit.com Like this post? subscribe to the feed.

1 Comment »

  1. 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!

    Comment by feydr — May 9, 2008 @ 2:19 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image

Powered by WordPress