I’ve previously had the need to validate, that at least on record in a has_many association existed. For that I used a custom validator. But today i realized that the presence validator in rails 3 will do exactly that:
class Parent < ActiveRecord::Base has_many :children validates :children, :presence => true end
If you need a custom message, that’s built into the new validation syntax for rails 3:
validates :children, :presence =>
{ :message => 'there should be at least one child' }
Simply wanted to share this, just in case it could save someone the hassle of building a custom validator.
great tip! thanks!
Thanks Jeppe