For this homework, you will build upon the models from the previous homework to create an actual working web app—mainly by adding controllers and views. Moreover, you will continue to practice with the version-control system, Git.
You will do this homework as a team; however, each member of your team will be responsible for the completion of a particular task.
Each team member will choose one task from the list below to complete. All team members must do a different task. If your team has only three members, then ignore Task 4.
For this homework, there will be four tasks (Tasks 1 through 4), each of which will build upon the corresponding task from Homework 4. As a reminder, here are the model classes and their associated tasks from Homework 4:
Task 1:
Task 2:
Task 3:
Task 4:
In particular, each task must do the following.
In the previous homework task, you added validations to only one of the model classes. For this homework, you must add validations to the other model class. In particular, you must add one validation per attribute of the class, and each validation must be of a different type. For example, the first attribute might have a length
validation, the second might have a format
validation, the third might have an inclusion
validation, and the fourth might have a numericality
validation.
Additionally, you must also create unit tests for these new validations. In particular, you will treat these validations the same as you did for the last homework—that is, for each validation, you must write one test that violates the validation rule.
Create 5 different seed-data objects for each model class (i.e., in db/seeds.rb
) for a total of 10. Be sure to use the create!
method (with a !
) to create them, so you will get error messages if a validation error occurs.
Create two controllers, each corresponding to a model class. Each controller must have the standard controller actions/pages detailed in class:
index
show
new
/create
edit
/update
destroy
The pages must have the features demonstrated in class, including inter-page links and notice/alert/error message handling. Be careful to follow the standard Ruby/Rails naming conventions.
As additional constraints, you must:
Create your controller actions and view ERBs by hand (i.e., not using scaffold
).
Along those lines, your controller actions may not mention json
, nor may you use the resource method in config/routes.rb
.
In addition to the standard actions/pages, you must do the following for each of your controller classes:
Add an action lucky
that randomly chooses a model object from the database and redirects the browser to the show
page for that object. (Note that you are doing an HTTP redirect in this case and not rendering a view.)
Add a route such that, if the controller class is FoosController
, it routes from the URL pattern /foos/lucky
to the lucky
controller action. It should also have the prefix lucky_foo
.
Add a hyperlink to the bottom of the index
page that says “I feel lucky” and links to the lucky_foo_path
. You should use the link_to
helper method to create this hyperlink.
IMPORTANT: Be sure to add your university username (e.g., mine is “sdflming”) in a code comment at the top of your controller class files. (Otherwise, how will we know which work is yours?)
Furthermore, you must add hyperlinks to your controllers’ index pages on the project home page. This will enable visitors (and graders) to conveniently navigate to each team member’s pages.
Before you can submit, all team members must have merged their code into the master branch and pushed the updates to GitHub. If a team member does not complete his/her work on time, you may submit without his/her contribution.
To submit your team’s work, you must “tag” the current commit in the master branch:
git tag -a hw5v1 -m 'Tagged Homework 5 submission (version 1)'
git push origin --tags
To grade your work, I will check out the appropriate tag, and run it on my machine.
Note that if for some reason you need to update your submission, simply repeat the tagging process, but increment the version number (e.g., hw5v2
, hw5v3
, hw5v4
, etc.).
Total marks: 100
Below, the top-level number is the items total point value. If an item is not submitted at all, 0 points will be awarded for that item. The sub-bullets indicate standard deductions for errors in a submitted item. The deduction list below may not be complete because there may be mistakes that we did not expect. The deduction for an unexpected mistake will be assessed at the time it’s discovered and will reflect how severe the instructor thinks the mistake is.
scaffold
: -20luck
action: -10luck
action: -1 to -10index
page: -5 eachOther deductions:
index
page: -5 each