Rails 3.1 submit ajax form (remote: true) with link

When working with ajax on a rails 3.1 application, I need to provide an ajax form (with remote: true) using a link, not a submit button.

What do I need to do for the link (or form) so that it appears as ajax, and not as a regular form? I tried adding onclick java to the link, but in each case it just submits the form in a non-ajax way (page refresh).

The ajax form currently works fine with the submit button, so it should be something small ...

Thank!

+3
source share
1 answer

:remote => true, Ajax submit . javascript . - :

<%= 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 %>
+6

All Articles