Autosubmit a form via AJAX (Rails 3.1)


I have a form with only a checkbox. When the user clicks this checkbox I
want to submit the form through AJAX. It’s like a TODO-list where you
mark the item as done by ticking a box.

So, how can I do this? :slight_smile: I’m using Rails 3.1.

I guess there is no native function to achieve this. So far I have this:

My form in the view:

<%= form_for [@list, item], :remote => true do |f| %>
<%= f.check_box :status %>
<% end %>

Then in my javascript file I guess I need to do something like (coffee):

$(‘input#item_status’).live ‘click’, (e) ->

form = $(this).parent('form')


Any ideas?


just run submit()

$(‘input#item_status’).live ‘click’, ->

param (e) is not needed, even in coffee :slight_smile:


On Jul 19, 2011, at 21:31 , Linus P. wrote:

<%= form_for [@list, item], :remote => true do |f| %>

You received this message because you are subscribed to the Google G. “Ruby
on Rails: Talk” group.
To view this discussion on the web visit
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at

Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

Hehe great! I actually tried it in an onClick="" but that didn’t submit
form through AJAX so I didn’t think it would work when doing it directly
jQuery either :slight_smile: It does work indeed.

And I now I don’t need the param (e). It’s a habit to pass in case I
it. Otherwise I remove it :slight_smile:

Thanks for the quick help!