views:

60

answers:

0

I'm upgrading a rails2 application that has some inline javascript to rails3 that I'm having trouble converting to UJS. Specifically, I can't figure out how to call change_values.js.rjs when clicking on a radio button.

My rails2 code looks like this:

<%= form_tag do %>
        <%= radio_button_tag "shared_name", "1st_button", true, :onclick => {:action => :change_values, :id => @character.id} %>
        <%= radio_button_tag "shared_name", "2nd_button", false, :onclick => {:action => :change_values, :id => @character.id} %>
        <%= radio_button_tag "shared_name", "3rd_button", false, :onclick => {:action => :change_values, :id => @character.id} %>
        <%= radio_button_tag "shared_name", "4th_button", false, :onclick => {:action => :change_values, :id => @character.id} %>
        <%= radio_button_tag "shared_name", "5th_button", false, :onclick => {:action => :change_values, :id => @character.id} %>
<% end %>

As I understand it, the onclick handler has been removed from rails3 and if you want that functionality, you need to create a listener in application.js like so:

$('shared_name_1st_button').observe('click', respondToClick);
function respondToClick(event) {
  /* ?! */
}

But how do I get change_values.js.rjs to run from there?