2011-02-17 54 views
0

如何在用戶點擊一行時標記爲已查看的內容。 這裏是我想解釋的一個例子:http://www.dba.dk/dyr/hunde-og-tilbehoer/racehunde/race-labrador/嘗試點擊一行並返回。您會看到該行標有複選標記。所以你知道你已經看到了它。Rails&Javascript - 如何標記爲已閱讀或已閱讀的內容?

如何創建類似的東西?

+1

我們不打算給你一個「詳細的例子」,但我們會給你一般的指導,你可以回來的具體問題。 – meagar 2011-02-17 22:38:58

回答

0

您正在尋找保存AJAX歷史記錄狀態。兩個驚人的Rails和Javascript教程可以在這裏找到:

  1. http://railscasts.com/episodes/246-ajax-history-state

  2. http://railscasts.com/episodes/175-ajax-history-and-bookmarks

第一個鏈接將引用第二。

來自Ryan Bate的網站| 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}") %>";