How to mark something as viewed when a user clicks on a row. Here is an example what I am trying to explain: http://www.dba.dk/dyr/hunde-og-tilbehoer/racehunde/race-labrador/ Try to click on a row and go back. You will see the row is marked with a check sign. So you know you h开发者_开发百科ave seen it.
How to create something like it?
You're looking to save an AJAX history state. Two Amazing Rails and Javascript tutorials can be found here :
http://railscasts.com/episodes/246-ajax-history-state
http://railscasts.com/episodes/175-ajax-history-and-bookmarks
The first link will reference the second.
From Ryan Bate's Website | Railscasts.com
/* application.js */
if (history && history.pushState) {
$(function() {
$("#products th a, #products .pagination a").live("click", function(e) {
$.getScript(this.href);
history.pushState(null, document.title, this.href);
e.preventDefault();
});
$("#products_search input").keyup(function() {
$.get($("#products_search").attr("action"), $("#products_search").serialize(), null, "script");
history.replaceState(null, document.title, $("#products_search").attr("action") + "?" + $("#products_search").serialize());
});
$(window).bind("popstate", function() {
$.getScript(location.href);
});
});
}
/* products/index.js.erb */
$("#products").html("<%= escape_javascript(render("products")) %>");
document.title = "<%= escape_javascript("#{params[:search].to_s.titleize} Products by #{(params[:sort] || 'name').titleize} - Page #{params[:page] || 1}") %>";
精彩评论