如何在 rails 中禁用嵌套表单的服务器端验证

How to disable server side validation of nested form in rails

我已经对嵌套表单进行了服务器端验证。每个都有模型并在给定的服务器端验证中。 但是,保存时模型服务器端验证工作的主要形式,我已将其禁用。 但是,我也禁用了嵌套表单模型服务器端验证,但它不起作用。

 validates_presence_of   :user_mob, :message => 'please enter the mobile number.' ,unless: :skip_valid
    validates_presence_of   :address, :message => 'please enter the address.', unless: :skip_valid

//这是主模型

class 用户详细信息< ActiveRecord::Base belongs_to :u_user_details, :foreign_key => 'u_id'

validates_presence_of :year, :message => 'please enter the details.', unless: :skip_valid
validates_presence_of :user_name, :message => 'please enter the details.', unless: :skip_valid
validates_presence_of :user_address, :message => 'please enter the details.', unless: :skip_valid
validates_presence_of :user_mobile, :message => 'please enter the details.', unless: :skip_valid
validates_presence_of :user_type, :message => 'please enter the details.', unless: :skip_valid

结束

即使我给出除非:skip_valid 在 netsted 表单模型中。它不工作。 如何禁用嵌套表单模型服务器端验证。

validates_presence_of :year, :message => 'please enter the details.', if: ->(u) { u.commit == 'submit' 或 u.commit = = 'approve' 或 u.commit == 'reapply'}

我们可以这样做。