Skip to content

Instantly share code, notes, and snippets.

@trevorturk
Created August 24, 2010 21:42
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 23 You must be signed in to fork a gist
  • Save trevorturk/548387 to your computer and use it in GitHub Desktop.
Save trevorturk/548387 to your computer and use it in GitHub Desktop.
$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});
<%= form_for @thing, :remote => true do |f| %>
<%= f.check_box 'checked', :class => 'submittable' %>
<%= f.label :checked %>
<%= thing.name %>
<% end %>
class ThingController < ApplicationController
def update
@thing = Thing.find params[:id]
@thing.update_attributes params[:thing]
end
end
// we could highlight the checkbox to show it's been clicked:
$('#thing').css("color","yellow");
// or add the updated thing to a list:
$('#things').prepend('<%=escape_javascript render(@thing) %>');
@ouimetch
Copy link

Absolutely excellent tutorial. I used your tutorial to create the same type of behavior with a dropdown menu instead of a checkbox and it work beautifully! Thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment