Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View application.js
1 2 3
$('.submittable').live('change', function() {
$(this).parents('form:first').submit();
});
View application.js
1 2 3 4 5
<%= form_for @thing, :remote => true do |f| %>
<%= f.check_box 'checked', :class => 'submittable' %>
<%= f.label :checked %>
<%= thing.name %>
<% end %>
View application.js
1 2 3 4 5 6
class ThingController < ApplicationController
def update
@thing = Thing.find params[:id]
@thing.update_attributes params[:thing]
end
end
View application.js
1 2 3 4 5
// 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) %>');

god

THANK YOU. I have been struggling for hours now to find a simple example on how to do this. You are one of the few people who did not overcomplicate things. I also would like to point out that the "live" method is now deprecated in jQuery. I updated it per the instructions on this page and confirmed that it works. Just a note. Hope you're great, and thanks again!

$(document).on('change', '.submittable', function() {
$(this).parents('form:first').submit();
});

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
Something went wrong with that request. Please try again.