我想在保存之前通过确定用户是否填写了特定字段、下面的付款金额字段并在提交表单之前选择了 status =“Closed”来进行验证。如果他只做一个而没有另一个,那么表格不应该保存
编辑页面
<%= simple_form_for @invoice, :html => { :class => 'form-horizontal' } do |f| %>
<%= render "shared/error_messages", :target => @invoice %>
<%= f.association :customer, disabled: @invoice.persisted? %>
<%= f.input :due_date, as: :string, input_html: { class: "datepicker" }, disabled: @invoice.persisted? %>
<%= f.input :invoice_date, as: :string, input_html: { class: "datepicker" }, disabled: @invoice.persisted? %>
<%= f.input :payment_method, as: :select, :collection => [['Cash','Cash'],['Cheque','Cheque'],['In-House transfer','In-House transfer'],['Account Ledger','Account ledger']], :selected => ['Cash','Cash'] %>
<%= f.input :reference_no, :label => 'Payment Reference No', as: :string %>
<%= f.input :amount, as: :string %>
<%= f.input :payment_date, as: :string, input_html: {class: "datepicker"} %>
<%= f.input :status, as: :select, collection: Invoice::VALID_STATUS %>
VALID_STATUS = ['草稿','打开','关闭','无效'] Invoice.rb
我希望如果用户将状态更改为已关闭,他应该在表单中输入一个金额。用户不应该能够在不输入金额的情况下将状态更改为已关闭