I have an object called dealer.  Dealer has two fields dealer_number
and sub_dealer_number.  It must have 1 OR the other... but not both.
To validate this I have:

class Dealer < ActiveRecord::Base
  validate :dealer_id?

private
  def dealer_id?
    if number.blank? && sub_number.blank?
      errors.add_to_base("You must specify either a Dealer Number OR a
Sub Dealer Number.")
    elsif (number.length > 0) && (sub_number.length > 0)
        errors.add_to_base("You must specify either a Dealer Number OR
a Sub Dealer Number.")
    end
  end
end

This looks really messy to me.  Is there a better way?  Thank you for
your thoughts.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to