SimpleForm and error_notification
SimpleForm gem was removed and replaced with Rails 5.1 form_with in Book Two Version 4.1.0, Yet, SimpleForm and error_notification method still appear multiple times throughout the book.
Thanks for letting me know. I thought I caught all the changes. Could you let me know where Simple Form and the error_notification method still appear?
Searching through Book Two V4.1.0, error_notification showed up 2 times and SimpleForm showed up 16 times.
Thanks. I'm working on a revision of Chapter 19 the "Contact Form" chapter today and I will check for any residual mentions of Simple Form and error_notification.
With SimpleForm removed, validation behavior changed. Outdated texts are highlighted below in italic font.
- Try submitting the form with a blank name. You’ll see a warning message, “Please review the problems below.” The form cannot be submitted.
- Try submitting the form with an invalid email address such as “me@foo”. The form will re-display with a message, “Please review the problems below,” and next to the email field, “is invalid.” The form cannot be submitted.
- Combining SimpleForm error handling with ActiveModel validation is powerful. If validation fails after the form is submitted, the page will redisplay and SimpleForm will display an appropriate error message.
I think your intention is for next iteration of code and book to display a flash warning message if @contact.valid? is false, before rendering 'new' template.
I'm lost at this page, where mention of an error_notification method is made, but there is none visible in the code, and my app doesn't display any errors when I leave out name, email etc on the form.
@cmilr since SimpleForm gem isn't included, error_detection method is unavailable. Refer to create method in app/controllers/contacts_controller.rb. Since @contact.valid? is false if name, email, or content is missing, the visitor will just be redirected to the same form to fill in the required fields. Hence my above comments "I think your intention is for next iteration of code and book to display a flash warning message if @contact.valid? is false, before rendering 'new' template (again)."
Thanks, yeah I see that. I'm just hoping to hear for a workaround to get error notifications.
@cmilr Try this in ContactsController#create method: replace render :new with flash[:alert] = "Missing Name, Email or Message." redirect_to new_contact_path or redirect_to new_contact_path, alert: "Missing Name, Email or Message."