Individual Assignment 3: Full Birthday Tracking

For this assignment, you must augment your birthday tracking application to add some sophistication. The application should be able to detect conflicts – dates when you have more than one birthday to attend to. It should also validate the form input to make sure it is in the right format, and store birthdays as “Date” in the database.

Due: October 22, 2012


Part 0: Get Assignment 2 Working

This assignment builds on the results of Assignment 2. Therefore, you need to have a working copy of the code from Assignment 2. If you were unable you complete the assignment successfully, the instructor will make a working version available. You can choose to continue using your own code from Assignment 2, or to start from the code the instructor has provided. I strongly encourage you to use your own code if you completed the assignment; learning about someone else’s code takes a lot of work.

Part 1: Use real Dates

Modify the Person model to store the birthday as a Date type in the database rather than using a string. Make sure the input from the input form is correctly converted into a Date type.

Part 2: Add Families

Add a new model called Family. Each family can have multiple people in it. Add a new view page that allows people to create new Families. And modify the Person input view page to allow them to choose which Family the person being entered belongs to. The list of people and birthdays should include which Family a person is part of. (Note, this should be an explicit has_many relationship between models)

Part 3: Input Validation

You should modify your controller to validate that the form data is in the correct format. Strings are strings, names don’t contain spaces, none of the fields are blank, etc. Your application should display an appropriate error message when an incorrect input is detected.

Part 4: Conflict Detection

When viewing a single person, display of list of “conflicts” – of other people who share that same birthday. So, for example, my birthday is November 14th. So the page about me should list everyone else in the system who has the same birthday as me.

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.


At 5pm on the due date, I will collect the assignments out of the git repository <username>/assign3. 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

October 22, 2012 at 5pm

Frequently Asked Questions

How do I work with dates?
In your migration, you can declare a column in your database to be a date. This will be fine. You can access individual parts of the date through its methods:, date.month and date.year. Also, you can create forms for inputing dates using the date_select function:
  <%= f.date_field(:birthday) %>
How do I detect conflicts?
To get the list of all people, you can say Person.all. You can include clauses in this to limit this. For example, to only get people with the first name of “Rick”, you could do Person.where(:first_name => "Rick").all. To detect conflicts, you can limit it to only people with a specified birthday:
  @conflicts = Person.where(:birthday => @person.birthday).all

Then you can print out this list of people in your show view.

How do I move the code from the assign2 git repository to a new assign3 repository?
The easiest way is to create a new, blank assign3 repository, copy all of the files over, and then commit the changes.
  new_repo assign3
  cp -r assign2/* assign3

Then, edit your config/database.yml file to point to a new, assign3 database, run your existing migrations on that database, and commit your changes.

  nano config/database.yml
  rake db:migrate
  git add .
  git commit
  git push origin master