tommyd456
tommyd456

Reputation: 10673

Rails validate additional fields

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.

Upvotes: 0

Views: 41

Answers (1)

Joe Pym
Joe Pym

Reputation: 1836

Use validates_associated?

Have something like:

class Booking
  has_many :guests

  validates_associated :guests
end

class Guest
  validates :name, :presence => true
end

Upvotes: 2

Related Questions