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
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.
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.
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.
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):
Finally, on the index page, include a link to the “new birthday” page.
When writing code, you should always document what the code does, and why. There are two pieces to the documentation:
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:
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>/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
February 19, 2014 at 5pm
rails new assign2 -d mysql. The reason for this is that last bit –
-d mysqltells rails to automatically load the database connection drivers.
new_repo assign2. Then you can copy the folder using this command:
$ cp -r assign1 assign2
config/database.ymlfile 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)
<name>_urlfunction, 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
to create a URL for that specific person. This will automatically go to the show action in your
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.
workflow.txtfile and turn it in on time without it.