Reimplement CSVBase
to use method_missing
instead
of adding fields and accessors.
Submit a file csvbase.rb
containing your class and a file
test.rb
with a test program, as well as any .csv files that your
tests require. These files should be in a directory
hw2/problem1
.
10 points
Add ActiveRecord-style
links to CSVBase
. You need to support the following:
:class_name
)But don't do the singular/plural distinction and upper/lowercasing. Use
singular and CamelCase for all class and field/column names. Use Id for IDs,
e.g. Id
for the primary key and QuestionId
for a
foreign key.
For example, consider multiple-choice questions. A question contains many choices, one of which is the answer.
class Question < CSVBase has_many :Choice belongs_to :Answer, :class_name => :Choice end
Here are the CSV files: Question.csv, Choice.csv
You only need to supply two methods: find(id)
and
find_each
(which takes a block to which you yield each element).
Your database code need not be efficient.
The biggest challenge in this assigment is to deal with circular dependencies.
Submit a file csvbase.rb
containing your class and a file
test.rb
with a test program, as well as any .csv files that your
tests require. These files should be in a directory
hw2/problem2
.
25 points
Make a Rails application that allows a user to take a quiz consisting of all questions in a database table. Questions and choices are as in the preceding problem.
Generate the basic CRUD application, and on the initial screen, add a link “Take quiz”. Present the questions and collect the answers in any way you like, then show the user's score. You need not store the score.
Submit the entire application in a directory hw2/problem3
.
Supply a file transcript.txt that contains a list of the changes that you
made to transform the basic CRUD app to your solution. Add that file to the
directory hw2/problem3
.
20 points
Submit your entire homework repo (which has directories hw1
and
hw2
) to Mercurial in the usual way.
Note that this is individual work, not something you submit with your buddy.