gpt4 book ai didi

jquery - 浏览器不响应 destroy.js.erb

转载 作者:行者123 更新时间:2023-12-01 07:24:24 24 4
gpt4 key购买 nike

我有一个 Rails 3.2.3 应用程序,用于管理志愿者和事件。在我的一个观点中,我正在创建一个链接来破坏志愿者事件。我正在使用 data-remote=true。 Controller 正确运行,Rails 表示它正在渲染我的 destroy.js.erb,但文件中的我的脚本没有被调用。我的脚本试图删除 DIV 元素并更新跨度的内容。以下是一些详细信息:

我的查看代码:

<%= link_to '', event, method: :delete, confirm: "Are you sure you want to delete this  volunteer posting?", title: event.name, class: "icon-remove", remote: true%> </li>

我的 Controller 代码: ...

respond_to  :html, :js

def destroy
@volunteer_event = VolunteerEvent.find(params[:id])
@volunteer_event.destroy

respond_with(@volunteer_event)

end

我的destroy.js.erb

$("#hours_worked_total").html("<%= @volunteer_event.worker.account.total_hours_worked %>")

$("#volunteer_posting-<%=@volunteer_event.id %>")
.fadeOut ->
$(this).remove()

这是在 View 中构建的结果 HTML:

<ol class="events">
<div id="volunteer_posting-48">
<li><strong>9808</strong> worked on August 5, 2012 by <i>Louie Ferry</i> for a total of 5 hours.
<a href="/volunteer_events/48" class="icon-remove" data-confirm="Are you sure you want to delete this volunteer posting?" data-method="delete" data-remote="true" rel="nofollow" title="9808"></a> </li>
</div>
</ol>

这是服务器日志:

Started DELETE "/volunteer_events/48" for 127.0.0.1 at 2012-05-08 11:17:50 -0400
...
Rendered volunteer_events/destroy.js.erb (2.7ms)

这是浏览器请求和响应:

Response:
$("#hours_worked_total").html("0")


$("#volunteer_posting-48")
.fadeOut ->
$(this).remove()

Content-Type:text/javascript; charset=utf-8

最佳答案

您在 erb 文件中使用了 Coffeescript。将其重命名为 destroy.js.coffee,或按如下方式更改:

$("#hours_worked_total").html("<%= @volunteer_event.worker.account.total_hours_worked %>");

$("#volunteer_posting-<%=@volunteer_event.id %>").fadeOut(function(){
$(this).remove();
});

关于jquery - 浏览器不响应 destroy.js.erb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501604/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com