Skip to content

Instantly share code, notes, and snippets.

@adamrobbie
Created September 1, 2012 12:53
Show Gist options
  • Save adamrobbie/3572520 to your computer and use it in GitHub Desktop.
Save adamrobbie/3572520 to your computer and use it in GitHub Desktop.
Render view asynchronously.
First put an empty, placeholder div in the main response
<div id="pink-dancing-elephants"></div>
and then add a little jQuery to the page
$.ajax({
url: "/elephants/dancing",
cache: false,
success: function(html){
$("#pink-dancing-elephants").append(html);
}
});
and have the action that responses to /elephants/dancing/pink return the blob of HTML that you want to have fill up the div. In the action that is invoked by the AJAX request, you'll want to render with :layout => false to keep the returned blob of HTML from including the entire frame. E.g.
# elephants_controller.rb
def dancing
@elephants = #whatever
render :layout => false
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment