Learn to handle and display form errors. Discover how to work with the array-like errors structure on all ActiveRecord objects, and see how Rails determines if an object is valid and considered acceptable for saving to the database. Render errors in the template so that user’s will know about problems with the data and have the opportunity to fix them.
- In this movie we'll learn how…to handle and display form errors.…When we're talking about form errors,…what we're really talking about are reasons why an object…can't be saved to the database.…We aren't going to talk about data validation…until the next chapter but we can get started…by using a very simple validation,…which is validates_presence_of :name.…We'll add that to our subject model.…That will require that the subject has some value…for the name attribute or else Rails won't allow it…to be saved to the database.…Not only will the save or update fail…but Rails will add an error to object.errors…which is an array-like structure for holding…any validation errors.…
Remember, in our controller after a save or update fails,…we're going to re-render the form to give the user…a chance to fix any problems with the form…and try submitting again.…We'll also have access to object.errors…and can use it to display information…about exactly which problems need fixing.…Without the display of those errors…the user would be left wondering what went wrong,…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.