Rails: resource management via tabs/ajax
Traditionally, a resource's index displays all of its objects, which you click to be taken to their respective show (or edit, delete, etc) methods. Instead, our interface is more iPad-like (or Lion's new Mail app), in the sense that the index displays all of its objects as tabs on the left, with a large c开发者_StackOverflowontent area on the right. Clicking an object fills the right content area with that object's show partial.
It seems to me that this will just require changing the show (and edit, etc) link_to
's to :remote => true
which will invoke show.js.erb
which replaces the right-hand content with the new show partial.
// show.js.erb
$('#right').html(' <%= render :partial => "show" %> ');
Assuming that is the best way (?), it means a ***.js.erb
file is needed for nearly every controller action of every resource that we want to have this behavior. Anyway to DRY that up?
$("#right").html("<%= escape_javascript(render("show")) %>");
I recommend this Right way on rails-3.
精彩评论