Integrates jquery.form with the Rails asset pipeline.
Supports AJAX form submission. Also submits form with file field with AJAX request.
ajax_submit_rails version | jquery.form version | required jQuery version |
---|---|---|
0.2.0 (LATEST) | 4.3.0 | v1.7.2 or later |
0.1.1 | 3.51.0-2014.06.20 | v1.5 or later |
0.1.0 | 3.51.0-2014.06.20 | v1.5 or later |
Add this line to your application's Gemfile:
gem 'ajax_submit_rails'
And then execute:
$ bundle
Rails app with Asset Pipeline
If you're using the asset pipeline,
then you must add the following line to your app/assets/javascripts/application.js
.
//= require jquery.form.min
Some people may need to add the extension to make it work
//= require jquery.form.min.js
You can also include unminified version (not recommended)
//= require jquery.form
Rails app without Asset Pipeline
Include javascript in your layout file as following.
For example:
application.html.erb
<%= javascript_include_tag 'jquery.form.min' %>
application.html.haml
or application.html.slim
= javascript_include_tag 'jquery.form.min'
<%= form_for @your_object, html: {class: 'ajax-submit'} do |f| %>
// other form fields
<%= f.submit %>
<% end %>
$(function () {
// your other code
$(document).on('submit', 'form.ajax-submit', function(e) {
e.preventDefault(); // prevent native submit
$(this).ajaxSubmit();
});
});
No... That's it! Really!! You are done!!! 😄
Now your forms with ajax-submit
class will get submitted by ajaxSubmit()
Bug reports and pull requests are welcome on GitHub at https://github.com/AquisTech/ajax_submit_rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.