Skip to content

Commit 73ca46c

Browse files
committed
Update readme to make it more informative about usage
1 parent cf52f7f commit 73ca46c

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# AjaxSubmitRails
22

3-
Integrates [jquery.form](https://github.com/jquery-form/form) with the Rails asset pipeline.
3+
Integrates [jquery.form](https://github.com/jquery-form/form) with the Rails asset pipeline.
44
Supports AJAX form submission. Also submits form with file field with AJAX request.
55

66
## Version mapping
7+
78
|ajax_submit_rails version|jquery.form version|required jQuery version|
89
|---|---|---|
910
|0.2.0 (LATEST)|4.3.0|v1.7.2 or later|
@@ -19,14 +20,15 @@ gem 'ajax_submit_rails'
1920
```
2021

2122
And then execute:
23+
```bash
24+
$ bundle
25+
```
2226

23-
$ bundle
24-
25-
## Usage
27+
## Integration
2628

2729
### Rails app with [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
2830

29-
If you're using the [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html),
31+
If you're using the [asset pipeline](http://guides.rubyonrails.org/asset_pipeline.html),
3032
then you must add the following line to your `app/assets/javascripts/application.js`.
3133

3234
```javascript
@@ -43,10 +45,9 @@ You can also include unminified version (not recommended)
4345

4446
### Rails app without [Asset Pipeline](http://guides.rubyonrails.org/asset_pipeline.html)
4547

46-
Put this in your layout file.
48+
Include javascript in your layout file as following.
4749

4850
For example:
49-
5051
`application.html.erb`
5152

5253
```erb
@@ -58,12 +59,35 @@ For example:
5859
= javascript_include_tag 'jquery.form.min'
5960
```
6061

62+
## Usage
63+
64+
##### Add class as `ajax-submit` (or any other class you wish to bind) to the form
65+
```erb
66+
<%= form_for @your_object, html: {class: 'ajax-submit'} do |f| %>
67+
// other form fields
68+
<%= f.submit %>
69+
<% end %>
70+
```
71+
##### Add binding for `ajaxSubmit()` in application.js
72+
```javascript
73+
$(function () {
74+
// your other code
75+
76+
$(document).on('submit', 'form.ajax-submit', function(e) {
77+
e.preventDefault(); // prevent native submit
78+
$(this).ajaxSubmit();
79+
});
80+
});
81+
```
82+
##### Looking for more steps???
83+
No... That's it! Really!! You are done!!! :smile:
84+
Now your forms with `ajax-submit` class will get submitted by `ajaxSubmit()`
85+
6186
## Contributing
6287

63-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/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](http://contributor-covenant.org) code of conduct.
88+
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](http://contributor-covenant.org) code of conduct.
6489

6590

6691
## License
6792

6893
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
69-

0 commit comments

Comments
 (0)