rails has_many minimum collection size update validation

后端 未结 3 1963
闹比i
闹比i 2020-12-25 11:20

I have a has_many association that accepts nested attributes. I need for there to be a minimum of 1 associated object in the collection, so I wrote a custom va

3条回答
  •  温柔的废话
    2020-12-25 12:20

    A better way to validate the minimum size of a collection:

    validates :my_association, :length => { :minimum => Fixnum}
    

提交回复
热议问题