RenderAsync
Lets you render paths asynchronously in Rails with an AJAX call. You use it like this:
# routes.rb:
match 'articles/counter' => 'articles#counter', :as => :articles_counter
# ^ Of course you won't use match, but you get the idea.
# In a view template:
<%= render_async articles_counter_path %>
This will generate the following HTML:
<div id="render_async_1a931cec881377296672"></div>
<script type="text/javascript">
(function($){
div_elem = $("#render_async_1a931cec881377296672");
$.ajax({
url: "/articles/counter",
success: function(response, status) {
div_elem.html(response);
}
});
}(jQuery));
</script>
Requirements
RenderAsync depends on a footer-block in your application-wide template, like this:
<%= yield :footer %>
And it also depends on you having included jQuery on the page.
Installation
Add this line to your application's Gemfile:
gem 'render_async'
And then execute:
$ bundle
Or install it yourself as:
$ gem install render_async
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request