General Ajax Spinner for Rails
Using spinjs-rails
Add the gem to our Gemfile:
gem 'spinjs-rails'
Add the javascripts to the asset pipeline:
//= require spin
//= require jquery.spin
Create a global listener using behaviors:
# app/javascript/main.js.coffee
$ ->
$('[data-behavior~=ajax-spin').on 'click', ->
target = $(this).data('target')
$(target).spin('large')
Add the behavior to the view:
# app/views/general/index.html.slim
= link_to 'My Link', my_link_path,
remote: true,
data: { behavior: 'ajax-spin', target: '#target-element' }
...
#target-element
.some-content
Written by Troy Martin
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#