render_async

render_async lets you include pages asynchronously with AJAX

MIT License

Downloads
3.5M
Stars
1.1K
Committers
26
render_async - render_async can emit event after it's finished

Published by nikolalsvk about 7 years ago

You can now pass in event_name to render_async.

<%= render_async users_path, :event_name => "users-loaded" %>

render_async will then emit event with that name after it's finished with fetching your content and appending your content to HTML.

Then you can easily execute JS code after render_async is completed with:

document.addEventListener("users-loaded", function() {
  console.log("Users have loaded!")
});
render_async - render_async drops jQuery dependency

Published by nikolalsvk about 7 years ago

render_async is now using vanilla JS to fetch your partials. You can now use it in projects that don't have jQuery.

Check it out on rubygems

render_async - Pass in a block to render_async

Published by nikolalsvk about 7 years ago

You can now pass in a block that will act as a placeholder.

If you want to add some feedback before your AJAX request is finished, passing a block is the way.

Example:

<%= render_async movie_path do %>
  <div class="cool-spinner"></div>
<% end %>

Now you will have the spinner (or anything you like) show before AJAX call finishes.

BREAKING_CHANGE:

This is a breaking change for those who relied on the <div> elements that we're rendered before
AJAX call.

Mentioned div element:

<div class="sk-spinner sk-spinner-double-bounce">
  <div class="sk-double-bounce1"></div>
  <div class="sk-double-bounce2"></div>
</div>

Those elements were there for spinner purposes but are removed from this version.

render_async - render_async inside tables

Published by nikolalsvk about 7 years ago

You can now put render_async inside tables!

Example:

<table>
  <tbody>
     <div>
        <tr>
          <%= render_async ... %>
        </tr>
    </div>
  </tbody>
</table> 
render_async - Support for caching

Published by nikolalsvk about 7 years ago

render_async now support caching. You can cache response from the AJAX call by using
render_async_cache instead of render_async helper.

In your views:

# app/views/comments/show.html.erb

# note 'render_async_cache' instead of standard 'render_async'
<%= render_async_cache comment_stats_path %>
# app/views/comments/_comment_stats.html.erb

<% cache render_async_cache_key(request.path), :skip_digest => true do %>
  <div class="col-md-6">
    <%= @stats %>
  </div>
<% end %>
render_async - Added html_options

Published by nikolalsvk over 7 years ago

render_async takes two arguments, path and html_options.

  • path is the ajax-capable controller action you're looking to call via get. e.g. comments_stats_path, posts_path, etc.
  • html_options is an optional hash that gets passed to a rails javascript_tag, to drop html tags into the script element.

Example utilizing html_options with a nonce:

<%= render_async users_path, nonce: 'lWaaV6eYicpt+oyOfcShYINsz0b70iR+Q1mohZqNaag=' %>
render_async - Removed obsolete files

Published by nikolalsvk over 7 years ago

Removed obsolete files and a git submodule from the gem