我有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} %>');
基本上,你沒有處理錯誤,如果有錯誤,你應該再次渲染表單,不顯示部分輸出數據。 –