Hi Everyone, Ran into an interesting case last night, and I was hoping that someone on the list here could give me some guidance. I''ve got a Polymorphic association for Addresses (which can belong to two different models). The catch is, one model requires a strict, precise address, and the other only requires a City, State and Postal Code. I want to use :validates_presence_of :street, :city, :state, and :postal_code, but only if the instance is being assigned to the model requiring stricter address validation. Any thoughts? -Jared --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jared wrote:> I''ve got a Polymorphic association for Addresses (which can belong to > two different models). > > The catch is, one model requires a strict, precise address, and the > other only requires a City, State and Postal Code. > > I want to use :validates_presence_of :street, :city, :state, and > :postal_code, but only if the instance is being assigned to the model > requiring stricter address validation.You can pass an :if => :strict_address_required? parameter to each relevant validates_presence_of call, and then define a method that looks like: def strict_address_required? if addressable_type == "Person" true else false end end Chris --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---