On 1/27/06, Duane Johnson <[EMAIL PROTECTED]> wrote: > > On Jan 27, 2006, at 9:03 AM, Norman Timmler wrote: > > > Today i came to point where nested validation could make my code more > > DRY. My question is, if anything like this planed? > > > > Example: > > > > Maybe you only want to display different error messages if an > > attribute > > is blank or has the wrong format. > > > > validates_presence_of :email_address, :message => 'Give me an > > address!' > > validates_format_of :email_address, :with => /[EMAIL PROTECTED],}/, > > :message => 'Something's wrong with your address!' > > > > This will give both messages if email_address is blank. The common way > > to get the second message only if email_address is not blank would be > > something like this: > > > > validates_presence_of :email_address, > > :message => 'Give me an address!' > > validates_format_of :email_address, > > :with => /[EMAIL PROTECTED],}/, > > :message => 'Something's wrong with your email!', > > :if => '!record.email.blank?' > > > > This could lead into multiple repetitions if you have more complex > > conditions or multi-level nested validations. Couldn't a nicer and > > simpler syntax be: > > > > validates_presence_of(:email, :message => 'Give me an address!') do > > validates_format_of :email, :with => /[EMAIL PROTECTED],}/, > > :message => 'Something's wrong with your email!' > > end > > > > Maybe i missed something that already exists. Maybe this approach > > is not > > convertible. What do you think about this block syntax? > > > > -- > > Norman Timmler > > Wow, I really like that. I suspect it will be difficult to implement > given the current validation code, but it would be a really sweet > addition to the tools we've got. > > -- Duane > _______________________________________________ > Rails-core mailing list > Rails-core@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-core >
Seconded! In fact, I think this would be an interesting project for me; unless someone else is working on this already (Norman?), I'd love to try my hand at it. Dave -- Dave Goodlad [EMAIL PROTECTED] or [EMAIL PROTECTED] http://david.goodlad.ca/ _______________________________________________ Rails-core mailing list Rails-core@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-core