0

Using Rails 4 I have a form that submits data to a Booking model. However, the form also submits an email address and this is intended for the Guest model.

I am ok inserting data into each table on submission of the form but my problem arises when I want to validate the data.

I haven't got a clue where to begin when trying to handle this extra parameter. Should I validate the email address using the Booking model (and if so how?) or should I somehow point the email part of the form to the Guest model and validate is separately?

I really am not sure how to approach this issue and any advice would be much appreciated.

1 Answer 1

2

Use validates_associated?

Have something like:

class Booking
  has_many :guests

  validates_associated :guests
end

class Guest
  validates :name, :presence => true
end
Sign up to request clarification or add additional context in comments.

2 Comments

I added this validates_associated :guest, :message => "Please enter your email address - but the error message displays with the word "Guest" at the beginning.
Try looking here @tommyd456 stackoverflow.com/questions/808547/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.