【发布时间】:2015-11-20 11:55:53
【问题描述】:
我的代码现在是这样的:
_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
当我点击表格行时,它会重定向到编辑表单。但是由于没有可用的相应模板,它会引发 模板丢失 错误:
缺少模板报告/编辑、使用 {:locale=>[:de]、:formats=>[:html]} 应用/编辑,...
我可以将此行设为可点击的远程链接吗?
(没有在它通过的行内实现某种隐藏链接)
更新
感谢@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
...
【问题讨论】:
标签: jquery ruby-on-rails ruby-on-rails-4