Validate number of nested attributes

Posted by Damien MATHIEU on Stack Overflow See other posts from Stack Overflow or by Damien MATHIEU
Published on 2010-04-07T21:10:53Z Indexed on 2010/04/07 21:13 UTC
Read the original article Hit count: 225

Hello,

I have a model with nested attributes :

class Foo < ActiveRecord::Base
    has_many :bar
    accepts_nested_attributes_for  :bar
end

It works fine. However I'd want to be sure that for every Foo, I have at least two Bar. I can't access the bar_attributes in my validations so it seems I can't validate it.

Is there any clean way to do so ?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about ruby-on-rails