Homework: H5 MVC Model
For this homework, you will create simple model classes in Rails, create seed records for those models, create index
and show
actions that render webpages that display the records (either individually or as a group), and 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. For each one of them:
- Create the model class as specified in a UML class diagram.
- Run the migrations to update the database and schema file.
- Write code to create seed records for the model as specified.
- Populate the database with the seed data.
- Create a controller for the model.
- Create an
index
controller action (with corresponding route and view) that renders a webpage that displays all records in the database and is formatted as shown in a figure. - Create a
show
action (with corresponding route and view) that renders a webpage that displays an individual record by ID and is formatted as shown in a figure. - Once you have completed the task, commit the current version of the code to your local repo, and push the changes to the remote GitHub repo.
Task 1: Book Model
- Figure 1.1 depicts the model class you must create.
- Table 1.1 lists the seed records you must write code to create.
- Figure 1.2 depicts how the page rendered by the
index
action should look. Hint: each group of sub-bullets is actually a unordered list (ul
) element nested within a top-level list item (li
) element. - Figure 1.3 depicts how the page rendered by the
show
action should look.
title | publisher | publication_date | isbn | genre |
---|---|---|---|---|
American Gods | William Morrow, Headline | 19 June 2001 | 0-380-97365-0 | Fantasy |
Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch | Gollancz (UK) / Workman (US) | 1 May 1990 | 0-575-04800-X | Comedy |
The Colour of Magic | Colin Smythe | 24 November 1983 | 0-86140-324-X | Fantasy |
Task 2: Author Model
- Figure 2.1 depicts the model class you must create.
- Table 2.1 lists the seed records you must write code to create. Hint: the
webpage
anddod
attribute values are optional, and when absent, should be set tonil
. - Figure 2.2 depicts how the page rendered by the
index
action should look. Hint: the records presented in an HTMLtable
element. In particular, the following HTML elements were used to construct this table:table
,thead
,tbody
,tr
,th
, andtd
. Note thatnil
attribute values appear as “N/A
” in the table. - Figures 2.3a and 2.3b depict how the page rendered by the
show
action should look. Note how thenil
attributes are handled.
first_name | last_name | webpage | dob | dod |
---|---|---|---|---|
Terry | Pratchett | nil | 28 April 1948 | 12 March 2015 |
Neil | Gaiman | http://neilgaiman.com/ | 10 November 1960 | nil |
J. K. | Rowling | http://jkrowling.com/ | 31 July 1965 | nil |
Task 3: Review Model
- Figure 3.1 depicts the model class you must create.
- Table 3.1 lists the seed records you must write code to create.
- Figure 3.2 depicts how the page rendered by the
index
action should look. Hint: the following HTML elements were used to construct this page:h1
,h2
,p
, andpre
. Note how thescore
was rendered as filled and hollow stars (i.e., ★ and ☆). Also, to achieve the format of thefull_text
part, thepre
tag will need to have an attributestyle="white-space: pre-wrap; font-family: serif;"
. - Figure 3.3 depicts how the page rendered by the
show
action should look. Note that the formatting is essentially the same as that used on theindex
page.
score | summary | full_text |
---|---|---|
5 | This grand tale of ancient gods struggling to survive in today's USA has a chilly setting but provides a great summer escape. |
Beaches, like books, offer a dislocation from reality, and when taken together the effect is multiplied many times. I love getting lost in a narrative then being jarred out of it by a noisy fellow holidaymaker and looking up, blinking, to remember I'm lying awkwardly on a towel on some sun-kissed shore, miles from home. Like the terra firma of a beach bordering the seemingly endless sea spooling out and away from the land, Neil Gaiman's American Gods offers that same sense of being anchored to reality but at the same time being merely a bulwark against something massive and frightening and ultimately unknowable. It seems a little odd now, given his ubiquity, but when American Gods was published in 2001 Gaiman wasn't a household name, unless your household happened to be filled with long-boxes of the comic books on which he had built his career. It wasn't his first, but American Gods feels like his first proper novel; previous outings had been Neverwhere, which was essentially a novelisation of his own screenplay for a BBC TV production whose budget never quite matched his imagination, and Stardust, a slight (though satisfying) fairytale originally conceived as an illustrated book with the artist Charles Vess. |
4 | Gaiman's storytelling is the furthest thing from clumsy — extremely well researched, superbly clever, and endlessly fun — so American Gods is a con worth falling for. |
Gaiman's cast of "old gods" includes gods from all over the world. There's Odin, of course, along with a number of others from Norse mythology. There's also Anansi from African folklore and Bilquis, the Bible's Queen of Sheba, and many, many more. Gaiman handles them all brilliantly, but what's really genius is how he gives them a back story. The novel's epigraph poses the question of "what happens to demonic beings when immigrants move from their homelands”; Gaiman takes this question and runs with it. His answer is that these "demonic beings” don't just appear on American soil. They migrate here, carried from other continents in the minds of their believers. These days, life ain't easy for the old gods. They face stiff competition in the "new gods” — media and technology and drugs. People no longer believe in the old gods, so they no longer make sacrifices to them, so the old gods are fading away. The old gods must take a stand against the new gods or face elimination. We follow along as Wednesday and Shadow round up the troops in preparation for battle. |
2 | There is so much going on, so many little details to keep track of, and yet it still manages to come together quite nicely to form a great story about what it means to be human. |
Good Omens: The Nice and Accurate Prophecies of Agnes Nutter, Witch is a contemporary and comedic fantasy written by Neil Gaiman and Terry Pratchett in 1990. The collaboration between two of the finest fantasy authors of our generation is nothing short of brilliant, and while they both shared everything equally and did it for fun, Pratchett has said they wouldn't do it again for a big clock. The antichrist has been born, the four bikers of apocalypse have gathered, its the end of the world as we know it and its all happening in the small english suburb of Lower Tadfield. This is not the news the angel Aziraphale and the demon Crowley had been hoping for as they have become quite accustomed to their lives on earth and are starting to have second thoughts about the whole Armageddon thing. Despite being mortal enemies they decide to work together to help raise the antichrist in the hope that when it comes time for the apocalypse, the antichrist might just decide not to carry through with it. If only those meddling satanic nuns hadn't got to him first... |
Task 4: User Model
- Figure 4.1 depicts the model class you must create.
- Table 4.1 lists the seed records you must write code to create.
- Figure 4.2 depicts how the page rendered by the
index
action should look. Hint: the following HTML elements were used to construct the table:table
,thead
,tbody
,tr
,th
, andtd
. Also, theemail
hyperlink links to amailto:
URL (e.g.,mailto:homer@email.com
). - Figure 4.3 depicts how the page rendered by the
show
action should look.
first_name | last_name | |
---|---|---|
Homer | Simpson | homer@email.com |
Lisa | Simpson | lsimp@hotmail.com |
Bart | Simpson | bsmpson@memphis.edu |