I have a form where the user can add email addresses separated by a ','.
I process the emails in the controller:
email_arr = extract_emails
email_arr.each do |email|
unless @user.save
@email_err << email
@user.add_email_errors
end
In the User model:
def add_email_errors errors.add("#{email} is not a valid email address") end
On the form:
<%= error_messages_for :user %>
All this works fine except I am only getting the error message for the last email address. So if a user enters the following:
bademail.com, notvalidemail.ca, etc on the form.
The error message is: "notvalidemail.ca is not a valid email address"
How can I get a list of all the invalid emails?
Thank you in advance.