Skip to content

Instantly share code, notes, and snippets.

@jamesgecko
Forked from trevorturk/application.js
Created February 28, 2012 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesgecko/1929617 to your computer and use it in GitHub Desktop.
Save jamesgecko/1929617 to your computer and use it in GitHub Desktop.
Ajax forms
$('.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) %>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment