所以我一直在谷歌上搜索如何设置它们,最后我得到了这段代码。
<script>
$('#reportform')
.bind("ajax:success", function(data, status, xhr) {
$('#reportalert').text('Done.');
});
.bind("ajax:error", function(xhr, status, error) {
$('#reportalert').text('Failed.');
});
</script>
<h2>Review Driver</h2>
<p>Fill out your review of the driver</p>
<div class="hero-unit form-signin" id="reportformdiv">
<%= form_for(@report, html: { id: "reportform" }, remote: true, update:
{ success: "response", failure: "error"} ) do |t| %>
<p id="reportalert"></p>
<%= t.text_field :plant_site, placeholder: "Plant Site" %>
<%= t.text_field :route_number, placeholder: "Route Number" %>
<%= t.text_field :driver_name, placeholder: "Driver name if available" %>
<%= t.date_select :date_recorded, html: { class: "input-block-level" } %>
<%= t.text_field :action, placeholder: "Action taken" %>
<%= t.text_area :report_body, placeholder: "What you witnessed",
style: "height: 300px;",
class: "input-block-level" %>
<%= t.submit "File Report", class: "btn btn-primary btn-large" %>
<% end %>
</div>
但它不起作用,我不知道为什么,我确定我做错了什么,我是 RoR 的新手,我喜欢这样一个事实,即我可以声明这个遥控器:它本身的形式是真实的,一旦我弄清楚如何设置回调我会很好去 :) 提前谢谢。