2012-06-06 15 views
5

我使用Rails的3.2.1黑光燈應用未定義的方法`remote_function」

我想在我的link_to標籤調用remote_function。

<%= link_to_document document, :label=>document_show_link_field, :onclick =>  remote_function(:controller => 'catalog', :action => 'save_user_history') %> 

這給了以下錯誤

undefined method `remote_function' for #<#<Class:0x2ff0dc0>:0x2f4af38>. 

有誰知道爲什麼嗎?

回答

2

您可以隨時使用正常的link_to。

<%= link_to "Save User History", save_user_history_catalogs_path %> 

或者如果它是一個AJAX功能,這樣的事情:

<a id="save_user_history">Save User History</a> 

而在你的JavaScript文件:

$("#save_user_history").click(function() { 
    $.post("/catalogs/save_user_history", function(data) { 
    .... 
+0

在我的應用程序中,我有鏈接列表,每個鏈接都重定向到某個網頁。我想將訪問過的鏈接的URL存儲在我的數據庫中,我正在嘗試使用javascript onclick事件,但我無法調用所需的ruby方法。 – shaz404