2015-11-20 15 views
1

我的代碼看起來像這樣的時刻:錶行遠程數據鏈路

_index.html.erb

<tr class="clickable" data-link=<%= edit_patient_report_path(@patient, report) %> data-remote="true"></tr> 

edit.js.erb

$('#report-index').hide(); // #report-index => container with all reports 
$('#report-form').html("<%= escape_javascript(render 'form') %>").show(); // #report-form => container for report form 

report.js.coffee

$ -> 
    $(document).on 'click','.clickable', (event) -> 
    target = $(event.target) 
    if target.is(':not(a)') 
     if $(this).attr('data-link') 
     window.location.href = $(this).data('link') 
     else 
     ... 

reports_controller.rb

class ReportsController < ApplicationController 
    respond_to :js, :html 
    ... 
    def edit 
    end 
    ... 
end 

當我點擊表格行重定向到編輯形式。但沒有對應的可用模板,它拋出一個模板丟失錯誤:

缺少模板報告/編輯與應用/編輯{:區域設置=> [:德] :格式=> [:HTML]},...

我可以將此行改爲可點擊的遠程鏈接嗎?

(沒有實施某種隱藏鏈接的地方通過行內)

UPDATE

感謝@ user3506853幫助我解決我的問題:

report.js .coffee(更新後)

$ -> 
    $(document).on 'click','.clickable', (event) -> 
    target = $(event.target) 
    if target.is(':not(a)') 
     if $(this).attr('data-link') 
     $.ajax({ 
      dataType: 'script', 
      url: $(this).data('link') 
     }) 
     else 
     ... 

回答

0

如果你想tr可點擊,那麼你必須使用js代碼,如下所示: -

<tr data-href="<%= edit_patient_report_path(@patient, report) %>"></tr> 

$(document).on('click', '#table-id tr', function() { 
    var link = $(this).data('href'); 
    $.ajax({ 
     type: 'PUT', 
     url: link 
    }); 
});