Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleForm and error_notification #101

Open
simoncal-saas opened this issue Jul 19, 2017 · 8 comments
Open

SimpleForm and error_notification #101

simoncal-saas opened this issue Jul 19, 2017 · 8 comments

Comments

@simoncal-saas
Copy link

simoncal-saas commented Jul 19, 2017

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.

@DanielKehoe
Copy link
Member

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?

@simoncal-saas
Copy link
Author

Searching through Book Two V4.1.0, error_notification showed up 2 times and SimpleForm showed up 16 times.

@DanielKehoe
Copy link
Member

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.

@simoncal-saas simoncal-saas changed the title Simple Form and error_notification SimpleForm and error_notification Jul 20, 2017
@simoncal-saas
Copy link
Author

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.

@cmilr
Copy link

cmilr commented Aug 30, 2017

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.

@simoncal-saas
Copy link
Author

@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)."

@cmilr
Copy link

cmilr commented Aug 31, 2017

Thanks, yeah I see that. I'm just hoping to hear for a workaround to get error notifications.

@simoncal-saas
Copy link
Author

simoncal-saas commented Aug 31, 2017

@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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants