Ruby on rails 4 为什么escape_javascript在coffeescript中打印为文本?
我的目标是在delete之后使用Ajax呈现部分视图,以重新生成表及其分页。但是当我试图在我的Ruby on rails 4 为什么escape_javascript在coffeescript中打印为文本?,ruby-on-rails-4,coffeescript,haml,kaminari,Ruby On Rails 4,Coffeescript,Haml,Kaminari,我的目标是在delete之后使用Ajax呈现部分视图,以重新生成表及其分页。但是当我试图在我的schedules.js.coffee中这样做时: $(".delete_schedule").bind "ajax:success", -> $(this).closest('tr').fadeOut "slow", -> $("table tr.numbered_row:visible").each (i) -> $(this).children(".seq").te
schedules.js.coffee
中这样做时:
$(".delete_schedule").bind "ajax:success", ->
$(this).closest('tr').fadeOut "slow", ->
$("table tr.numbered_row:visible").each (i) ->
$(this).children(".seq").text i + 1
$("#schedules").html('#{ escape_javascript render("schedules")}')
$("#paginator").html('#{ escape_javascript(paginate(@schedules, :remote => true).to_s)}')
输出的页面源如下所示:
<tbody id="schedules">#{ escape_javascript render(:partial => "schedules")}</tbody>
<div id="paginator">#{ escape_javascript(paginate(@schedules, :remote => true).to_s)}</div>
我的主要观点是:
index.html.haml
%h2 Your schedules
- @i = 0
.table-responsive
%table.table.table-striped{:id => "schedules_table"}
%thead
%tr
%th No
%th Day
%th Start
%th End
%th Away?
%th Action
%tbody{:id => "schedules"}
= render :partial => 'schedules'
%br/
%div{:id => "paginator"}
= paginate @schedules, :remote => true
%br/
= link_to 'New Schedule', new_location_schedule_path
|
\#{link_to 'Back', doctor_locations_path(current_doctor)}
我的部分观点是:
_schedules.html.haml
- @schedules.each_with_index do |schedule, i|
%tr.numbered_row
%td.seq= i + 1
%td
= schedule.find_day_name()
%td= schedule.start_time.strftime("%H:%M")
%td= schedule.end_time.strftime("%H:%M")
%td{:id => "#{schedule.id}"}
%a.status_link.btn.btn-danger.btn-sm{"data-href" => set_schedule_status_path(location_id: params[:location_id], id: schedule.id), :style => "#{schedule.is_away ? '' : 'display: none'}", :id => "#{schedule.id}"}
%i.fa.fa-times
%span Away
%a.status_link.btn.btn-success.btn-sm{"data-href" => set_schedule_status_path(location_id: params[:location_id] ,id: schedule.id), :style => "#{schedule.is_away ? 'display: none' : '' }", :id => "#{schedule.id}"}
%i.fa.fa-check-square-o
%span Available
%td
- concat link_to icon('pencil'), edit_schedule_path(schedule, location_id: params[:location_id])
- concat " | "
- concat link_to icon('remove'), [@location, schedule], method: :delete, remote: :true, data: { confirm: 'Are you sure?' }, :class => 'delete_schedule'
在哪里定义了
escape\u javascript
?如果它是一个Ruby函数,那么除非您将其作为模板处理,否则它不会运行。如果它是JS/CS函数,则需要在双引号中插入。@DaveNewton我认为escape\u javascript
是Ruby函数。如何将其作为模板处理?使其成为erb文件,但。。。无聊的。我以为服务器端生成的javascript模板在几年前就消失了?
_schedules.html.haml
- @schedules.each_with_index do |schedule, i|
%tr.numbered_row
%td.seq= i + 1
%td
= schedule.find_day_name()
%td= schedule.start_time.strftime("%H:%M")
%td= schedule.end_time.strftime("%H:%M")
%td{:id => "#{schedule.id}"}
%a.status_link.btn.btn-danger.btn-sm{"data-href" => set_schedule_status_path(location_id: params[:location_id], id: schedule.id), :style => "#{schedule.is_away ? '' : 'display: none'}", :id => "#{schedule.id}"}
%i.fa.fa-times
%span Away
%a.status_link.btn.btn-success.btn-sm{"data-href" => set_schedule_status_path(location_id: params[:location_id] ,id: schedule.id), :style => "#{schedule.is_away ? 'display: none' : '' }", :id => "#{schedule.id}"}
%i.fa.fa-check-square-o
%span Available
%td
- concat link_to icon('pencil'), edit_schedule_path(schedule, location_id: params[:location_id])
- concat " | "
- concat link_to icon('remove'), [@location, schedule], method: :delete, remote: :true, data: { confirm: 'Are you sure?' }, :class => 'delete_schedule'