Homework: H7 Forms for Creating New Model Records
For this homework, you will continue to build upon the Rails app from the previous homework by adding model validations to prevent bad data from being saved to the database and by writing model tests to verify that the model code you create works correctly. Additionally, you will practice using the basic version control features of Git.
The tasks you will perform draw heavily from this demonstration:
The specific tasks are detailed below, and each one refers to a model class from the last homework. For each task you must do the following:
- Implement a
new
action/view that displays a form for saving new instances of the model class to the database. Note that the Action View Form Helpers Rails Guide mentions form helpers for dates, emails, and URLs in addition to basic text field and text area form helpers. - Implement a
create
action that tries to save submitted form data to the database. On a successful save, the action should redirect the browser to theindex
page. If saving fails (e.g., due to a validation failure), the action should re-render the form. - Using the flash, display a success or error message after form submission.
- Add a hyperlink to the
index
page that links to thenew
form page. - In cases where form submission fails due to a validation failure, the re-rendered
new
view should retrieve the error messages from the model object and print them along with the error flash message.
Task 1: Book Model
- Figure 1.1 depicts the model class for which you must create validations.
Task 2: Author Model
- Figure 2.1 depicts the model class for which you must create validations.
Task 3: Review Model
- Figure 3.1 depicts the model class for which you must create validations.
Task 4: User Model
- Figure 4.1 depicts the model class for which you must create validations.