I'm currently writing a rails app for managing events. An event keeps track of all of the people objects attending. Now, I want to ensure some properties of the person before adding it to the array of people in events. How can I do this?
This is the function for adding a person to an event:
def update
@event = Event.find(params[:id])
email = params[:event][:people][:email]
person_array = Person.where(email: email)
if ! person_array.empty?
@event.people.push(person_array[0])
end
redirect_to @event
end
I want to check the persons age, uniqueness in the array and want to check if the person exists.