0

I'm using Rails UJS to load partials into a container depending on the link I click. I've got everything working (see my answer to my question here for code) but I'd like to add a spinner while the content is loading. How can I go about doing this? I found a brief example in Simone Carletti's post on UJS but can't seem to implement it properly.

Here's the HTML generated:

<div id="tabs">
  <ul id="infoContainer">
    <li><a href="/profiles/1/profile_reviews" class="active" data-remote="true" id="profile_loader">Reviews</a></li>
    <li><a href="/profiles/1/profile_about" class="inactive" data-remote="true" id="profile_loader">About</a></li>
    <li><a href="/profiles/1/profile_credits" class="inactive" data-remote="true" id="profile_loader">Credits</a></li>
    <li><span id="loading">Loading...</span></li>
  </ul>
  <div id="tabs-1">
    # load data from partials here
  </div>
</div>

Can anyone help me out?

Community
  • 1
  • 1
tvalent2
  • 4,879
  • 9
  • 42
  • 83

1 Answers1

2

See this SO answer for more info, but the easiest thing to do is to bind to the ajax:before and ajax:after events to show/hide the spinner.

Whether to do this via the javascript_event_tag or by binding in an external JS file is a different issue.

Community
  • 1
  • 1
Dave Newton
  • 152,765
  • 23
  • 240
  • 286