I believe that this one was a bad example...

I found myself implementing this a couple times in the last year:

validate :a_or_b
>
> def a_or_b
>   if a? && b?
>     self.errors.add :a, "You can't choose both options at the same time."
>   end
> end
>

One of the cases was extremely common:

Choose something:
 [  ] Option 1
 [  ] Option 2
 [  ] Option 3
 [  ] Other <input type="text">

Each option would be an *option_id : integer*, and Other would be *other_option
: string* .

For that case :

validates :option_id, :absence => true, :if => :other_option?
validates :other_option, :absence => true, :if => :option_id?

Would fit perfectly! (Considering that at least one of them is obrigatory).

What do you think ?

-- 
Att,
Everton

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to rubyonrails-core@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-core+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to