我有AJAX创建新项目并在我看来更新它们。AJAX验证编辑/更新
我的模型验证在创建新模型时不会保存或提交。
但是,当我更新现有的字段时,它只会停止保存它,但会呈现带有“新”数据的ajax更新表单,从而给出它正在保存的印象。
当我刷新后,我看到变化得到了回滚。但这只是我想要的行为的一半。
我需要提交按钮被禁用。我怎样才能做到这一点?
我的表格样式是这样的:
<%= f.text_field :name, required: true, class: "mdl-textfield__input" %>
和我在模型验证是这样的:
validates_presence_of :name
我edit.js.erb
$("#education_<%[email protected]_education.id%>").replaceWith("<%= j render('new_employee_education_form')%>");
我的更新。 js.erb
$("#edit_employeeeducation_<%= @employee_education.id %>").replaceWith('<%= j render partial: "employeeeducation", locals: {employee_education: @employee_education} %>');
基本上,你没有处理错误,如果有错误,你应该再次渲染表单,不显示部分输出数据。 –