jQuery Rails 3 ...表单提交两次...删除两次...帮助 [英] Jquery Rails 3... form submits twice... deletes twice... help

查看:88
本文介绍了jQuery Rails 3 ...表单提交两次...删除两次...帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎eveyone遇到了这个问题,但没有人知道外行的术语,甚至没有适当的解决方案.

It seems like eveyone has this problem but no one has a laymans terms answer or even a proper solutions.

我有一个使用ajax提交表单并将其自动添加到文本字段下面的列表的表单.该表格提交了两次,所以我有两个相同的记录(除了ID).更糟糕的是,当您尝试删除它时,它不会更新页面,因为它试图两次删除同一记录.

I have a form that uses ajax to submit the form and automatically adds it to the list below the text field. The form submits twice so i have two identical (apart form the ID) records. Worse still is when you try to delete it wont renew the page because its tried to delete the same record twice.

我希望有人能给我一个很好的答案... 顺便说一句,我是新来的. 代码:

I hope someone has a great answer out there... btw im new to rails. code:

index.html.erb

index.html.erb

<h1>SSCC</h1>
<div id="orderline_form">
    <%= render 'form' %>
</div>

<ul id="orderlines">
    <%= render :partial => @orderlines.reverse %>
</ul>

_form.html.erb

_form.html.erb

<%= form_for(@orderline, :remote => true) do |f| %>
<div class="field">
    <%= f.label :Order_ID %>
    <%= f.text_field :order_id %><br/>
    <%= f.label :SSCC %>
    <%= f.text_field :sscc %>
</div>
<div class="actions">
    <%= f.submit %>
</div>
<% end %>

_order_line.html.erb

_order_line.html.erb

<%= content_tag_for(:li, order_line) do %>

<%= order_line.id %> |
<%= order_line.order_id %> |
<%= order_line.sscc %>
(<%= link_to 'Delete', order_line, :confirm => 'Are you sure?',
:method => :delete, :remote => true %>)

<% end %>

create.js.erb

create.js.erb

$('#orderlines').prepend('<%= escape_javascript(render(@orderline))%>');
$('#orderlines > li:first ').effect('highlight', {}, 3000);
$('#orderline_form > form')[0].reset();

destroy.js.erb

destroy.js.erb

$('#<%= dom_id(@orderline) %>').css('background', 'red');
$('#<%= dom_id(@orderline) %>').hide("fade", {}, 1500);

推荐答案

我碰巧将"application.js"存储了两次(.../public/assets/application.js和.../app/assets /javascripts/application.js). Rails 3.2.1 Asset管道对其进行了编译并创建了另一个.检查并删除不需要的内容.

It happened to me that "application.js" was stored twice (.../public/assets/application.js and .../app/assets/javascripts/application.js). The Rails 3.2.1 Asset pipeline compiled it and created another one. Check for that and delete the unneeded.

请记住,您可能已经拥有其他重复资产,您刚刚开始注意到这一点,因为jQuery使其显而易见.

Keep in mind that you might already have other repeated assets, you just started noticing this one because jQuery made it evident.

此链接对我有帮助:

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆