I have two related models : Group and Member.
Group.rb :
has_many :members, :dependent => :destroy
accepts_nested_attributes_for :members, :reject_if => lambda { |a| a[:email].blank? and a[:id].blank? }, :allow_destroy => true
What I want to do is adding a validation which prevents adding members as soon as members_count reaches 25.
So if I edit a Group, let's say for example :
- I have 20 existing members
- I add 8 more members from FORM at my browser end
It should saves the first 5 records and then raises an error such as "You have exceeded limit for the nested attributes".
Is there any built-in method in rails to do this. Being a comparatively newbie to rails I am not aware of this ??