Individual Assignment 2: Long-term Birthday Storage

For this assignment, you must create a very simple rails application. This application will ask users to input information about a birthday, and then create a dynamic webpage that contains that birthday information. This information will be stored in the database for others to use. This is basically the same as Assignment 1, except that we are storing birthdays in the database for future use.

Due: February 19, 2014

Requirements

Part 1: Create a new rails application

This assignment builds on the results of Assignment 1. Therefore, it is important that you get Assignment 1 working correctly, and understand how it works. This assignment is conceptually very similar to Assignment 1; however, since we are storing birthdays in long-term storage, the code will look very different. For this assignment, you should start with a brand new rails application.

Part 2: Create a Person resource

To store information about people, we need to create a Person model. This model should store the same information as your application from Assignment 1 collected: first name, last name, relationship, birthday.

Part 3: Input

Along with your Person model, you created a controller. Modify the controller (copying and pasting code, as appropriate, from Assignment 1) such that when a user submits information about a birthday, it gets stored in the database as a Person.

Part 4: Output

You currently have a page that displays birthday information. Modify this page to retrieve the data from a Person model that is stored in a single @variable.

In addition to your “new birthday” page, you will also need to create the following two views (and their associated actions in the controller):

  1. An index page that displays a list of all of the people in the database.
  2. Clicking on any single user should display a page just about that user. (a show action)

Finally, on the index page, include a link to the “new birthday” page.

Part 5: Documentation

When writing code, you should always document what the code does, and why. There are two pieces to the documentation:

  1. Write self-documenting code. It should be relatively easy to read your code and understand what it does. This means you should do things like:
    • Use meaningful and accurate names for variables and methods
    • Don’t put everything on one line. Put each separate step on its on line
    • Use whitespace. Leave blank lines in the code to conceptually group parts of the code.
  2. Write explicit documentation when appropriate:
    • Unless it is blatantly obvious, include a comment describing what each function does right above the function
    • Describe expectations. For example, one of your “action” methods in your controller expects to receive form data. Describe that data in the comment for that method
    • Anytime the code isn’t clear, use a comment to describe what the code is doing

In addition, for this assignment I would like you to create a file in the doc directory that describes the workflow of your application. This file should be named doc/workflow.txt it should be a plain text file. Basically, it should contain:

Part 6: Extras

You are not required to do any of these extras, but including one or more of them in your assignment will lead to extra credit.

  1. Sort the list of people by birthday
  2. Allow the user to specify the sort order: sort by last name, sort by first name, or sort by relationship.

Submission

At 5pm on the due date, I will collect the assignments out of the git repository <username>/assign2. Be sure that your assignment is in the repository, in the correct directory, and don’t forget to git commit and git push. Make sure the application runs on the server as part of my grading will be to run the program and enter birthday information into it.

Due Date

February 19, 2014 at 5pm

Frequently Asked Questions

Is it best to create a new application for Assignment 2, and then copy the code I need from Assignment 1 over? Or should I just copy the assign1 folder?
I suggest that you start by creating a new application with new_repo assign2 and rails new assign2 -d mysql. The reason for this is that last bit – -d mysql tells rails to automatically load the database connection drivers.
But I really want to copy assign1 over to assign2… How do I do that?
You need to create a new repository with new_repo assign2. Then you can copy the folder using this command:
$ cp -r assign1 assign2
If we copy assignment1 into a new directory called assign2, how do we tell it to use mysql database?
The only place you need to tell it is in the config/database.yml file. Edit that file to make it look similar to the config/database.yml file from Lab 4: Models. Once you’ve done that, you will have to also add the following line to your Gemfile (which is in the main directory of your application)
  gem 'mysql2'
How do I create a view for a single person?
We didn’t cover this in the lectures and labs so far. Part of this assignment is learning to go beyond exactly what we have covered and try to figure out how to do more. So here is some help. When using the <name>_url function, it is possible to pass an ID parameter. Remember that each instance of a model has an ID number automatically assigned to it. So if you have a Person stored in the variable @person, then you can use
  person_url(@person)

to create a URL for that specific person. This will automatically go to the show action in your people_controller. For example, when creating a list of people, you can use this to create a separate URL for each person in the list. Then, in the controller, you could create an action called show:

  def show
    id = params[:id]
    @person = Person.find(id)
  end

This will fill in the @person variable with the Person object that corresponds to the ID specified in the URL. You’ll have to write the view for this action on your own.

How important is getting the view for a single person working?
Well, it is part of the assignment. So you can’t get a great score if it isn’t working. However, it is only one small part of the assignment. You will lose more points if you turn in the assignment late than if you don’t have this working. So, try to get it working correctly, but if it doesn’t, say so in your workflow.txt file and turn it in on time without it.