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

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

ms access - C# - Using OleDbParameter on table name -