1

我試圖從rails 2.3到upgade,我發現在rails 2中link_to_remote應該更改爲link_to在rails 3中具有:remote => true屬性。link_to_remote屬性/參數在rails 3

而對於:before, :loading, :failure, :update

但我也有一個像:url, :href, :title屬性非侵入式JavaScript(UJS)我應該如何改變這種

這裏是軌道2.3代碼我試圖升級

<%= link_to_remote column.label, 
    { :url => sort_params, 
    :before => "addActiveScaffoldPageToHistory('#{href}', '#{controller_id}')", 
    :loading => "Element.addClassName('#{column_header_id}','loading');", 
    :failure => "ActiveScaffold.report_500_response('#{active_scaffold_id}')", 
    :update => active_scaffold_content_id, 
    :method => :get }, 
    { :href => href , 
    :title => column.header_info}%> 

我已經分析了很多網站和Rails文檔,但一切都沒有指定有關這些屬性的link_to

回答

0

可以綁定回調到Rails 3中的遠程鏈接,其餘的屬性可以分配爲選項。

link_to column.label, 
    sort_params, 
    remote: true, 
    title: column_header.info, 
    id: 'my_remote_link', 
    data: { 
    href: href, 
    controller_id: controller_id, 
    column_header_id: column_header_id, 
    active_scaffold_id: active_scaffold_id 
    } 

我們將使用回調的數據屬性。

$('#my_remote_link').bind('ajax:beforeSend, function() { 
    addActiveScaffoldPageToHistory($('#my_remote_link').data('href'), $('#my_remote_link').data('controller_id')); 
}); 

用於不同ajaxEvents的描述見http://docs.jquery.com/Ajax_Events