rails 3.1 submit an ajax (remote: true) form with a link

ajax, javascript, jquery, ruby-on-rails-3

Solution

When you create a form with `:remote => true` the Ajax event is bound to the submit button of the form. You must use javascript to trigger that event. Here is some code I used to accomplish something similar:

<%= form_for [item.list, item], :remote => true, :html => { :'data-type' => 'json', :id => 'change-completed-form' } do |f| %>
    <td><%= f.label :name, item.name %></td>
    <td><%= f.check_box :completed, :onClick => "this.form.submit_button.click();" %></td>
    <%= f.submit :id => 'submit_button', :style => 'display: none;' %>
<% end %>

Problem

Working with ajax on a rails 3.1 app, i need to be able to submit an ajax form (with remote: true) using a link rather than a submit button. what do i need to do to the link (or the form) to make it submit as ajax rather than a normal form submit? I have tried adding onclick java to the link, but in each case it simply submits the form in a non-ajax way (page refresh). The ajax form currently works fine with using a submit button, so it's got to be something small... Thanks!

Original source