Updating the page without update_page and rjs
So, with all this about using UJS and RJS being removed from rails 3.1, I am wondering 开发者_StackOverflow中文版how I will go about updating a relatively large amount of html on a page. Before I could just render a partial from the insert_html method, how should I do this now?
Use javascript, or any framework you like. I prefer jQuery.
$("#somediv").html("<%= escape_javascript(render :partial => "/path/to/partial") %>")
You can, for example, load it with jQuery's load method:
$('#somediv').load('/some/path');
There's a pretty nifty javascript partial page loader that @defunkt has put together.
It's called pjax. It enables partial page reloading and expected functionality with the back button for browsers that support history.pushstate API
what is it?
pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades.
pjax enhances the browsing experience - nothing more.
You can find a demo at http://pjax.heroku.com/
UJS, RJS, templates and helpers will still be supported via optional gems.
精彩评论