ruby on rails - get parent values in child model -



ruby on rails - get parent values in child model -

i have model called rsvpregistrations with

belongs_to :rsvp

i need utilize values parent 'rsvp' object in validations such as

validates_presence_of :phone if self.rsvp.phone

(rsvp.phone boolean)

but doesn't work. error undefined method `rsvp'. how can access parent object , values?

once working, have other similar validations run, i'm thinking need grab parent 'rsvp' 1 time , reference in other validations.

thanks in advance.

validates_presence_of :phone, :if => proc.new { |obj| obj.rsvp.phone? }

more options here

ruby-on-rails model-associations

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -