Project 6 - Ruby on Rails Web Database
Due Dec 9th, 2010
In this project, you will practice with server-side scripting using
a mixture of markup (HTML, XML) and scripting (eRuby) languages.
- Download the archive file
and extract its contents.
- For Windows:
- Download Instant Rails 2.0 as
Extract its contents by double-clicking on the icon, preferably to C:\InstantRails-2.0-win\.
- For non-Windows:
- You can still install Rails, but it will be more difficult
- Install Rails 2.0 by typing "gem install rails --include-dependencies" (directions here).
- You should be able to execute Rails directly to generate the
- If not already installed, you will need to install
a web server (e.g., Apache) and a database
server (e.g., MySQL) in order to actually run the web database.
- My recommendation is to just borrow a friend's Window's machine
for a day or so and use InstantRails.
- You can also directly edit & submit index.html.erb. You just
won't be able to actually test it on a web database.
Along with files used to make direct submissions to the
submit server (submit.jar,
submit.rb), you will
find the following project files:
- index.html.erb -
Your eRuby file (you'll need to download & edit it,
since your browser won't display it properly)
Your job is to set up a web database of guest comments
using Instant Rails, and modify the default web interface
displaying guest comments so that comments are displayed
in alphabetical order (by guest name), and also provide
all guest comments in XML format.
Part 1: Set Up Instant Rails
- Double click on C:\InstantRails-2.0-win\InstantRails.exe
to bring up the Instant Rails console.
- In the console, click on the "I" (to the left of the "Apache" button)
to bring up a menu (or alternatively, right-click on the
"I" icon on the bottom right of the screen).
Select "Rails Applications" -> "Manage Rails Applications" to bring up the Rails Applications console.
- In the Rails Applications console, click on "Create New Rails App..." button to bring up a command shell in the directory C:\...\rails_apps.
- In the command shell, type "rails guests". This will set up a number of scripts in a "guests" subdirectory.
- In the command shell, type "cd guests"
- In the command shell, type "ruby script\generate scaffold Message name:string comment:text".
This will generate the basic code for the web database.
The database model name will be message,
and it will have two columns (name & comment).
A view & a controller called messages will also be generated.
- In the command shell, type "rake db:migrate". This will create the
table for Message in the SQL database.
The InstantRails database uses sqlite3
(so you don't actually use MySQL).
- In the Rails Applications console, click on "Refresh List" button.
"Guest" should now appear in the list of Rails Applications.
- In the Rails Applications console, click on the checkbox next to "guest".
- In the Rails Applications console, click on "Start with Mongrel".
This will start a Ruby-based web server called
Mongrel that listens to port 3000 on your computer
(so you don't actually use Apache). If not using InstantRails,
you can start Mongrel by typing "script\server" from
the "guests" directory.
- Now bring up your web browser and type in the URL
If everything worked properly, this should bring you to the default web interface
for the guest comment database:
- Play around with adding guest messages (names & comments) to your database.
Note how you can add/edit/delete messages from the database, and the web page
is dynamically updated to reflect the content of the database.
- The actual file (index.html.erb) used to generate the web page
is in "C:\...\rail_apps\guest\app\views\messages\". It should be
identical to the file you received with your project.
Part 2: Add Features
For this project, you need to add two features to the web database.
You must implement your extension by editing index.html.erb, an eRuby file.
The file is an HTML file interleaved with Ruby code inside <% ...code... %> tags.
- Display guest comments in alphabetical order (by guest name).
The default order is the order comments were inserted in the database.
You may use standard Ruby Hashes, Arrays, and library functions such as sort!.
- Provide all guest comments in XML format at the bottom of the
web page. Use the XML tags <guests>, <guest>, <name>, and <mesg>. The guest elements should be sorted by guest name.
Any reasonable formatting (spaces, linebreaks) is fine. You may find
using the HTML document character set useful for displaying
characters that may otherwise be processed by your browser.
For simplicity, you may assume that every guest name is unique, and guests only leave a single comment.
- Input: Use the web interface the add the following guest messages (in order):
||Hillary for president
||Change we can believe in
- Original Output: Should resemble the following:
- Desired Output: Should resemble the following:
<mesg>Change we can believe in</mesg>
<mesg>Hillary for president</mesg>
You can submit your project in two ways:
Submit your file index.html.erb directly to the
by clicking on the submit link in the column "web submission".
Next, use the submit dialog to submit your index.html.erb file.
Select your file using the "Browse" button,
then press the "Submit project!" button.
Submit directly by executing a Java program on a computer
with Java and network access. Use the submit.jar file
from the archive
To submit, go to the directory containing your project, then either
execute submit.rb or type the following command directly:
java -jar submit.jar
You will be asked to enter your class account and password, then
all files in the directory (and its subdirectories) will be
put in a jar file and submitted to the submit server.
If your submission is successful you will see the message:
Successful submission # received for project 6
The Campus Senate has adopted a policy asking students to include the
following statement on each assignment in every course: "I pledge on
my honor that I have not given or received any unauthorized assistance
on this assignment." Consequently your program is requested to
contain this pledge in a comment near the top.
Please carefully read the academic honesty section of the
course syllabus. Any evidence of impermissible cooperation on
projects, use of disallowed materials or resources, or unauthorized
use of computer accounts, will be submitted to the Student
Honor Council, which could result in an XF for the course, or
suspension or expulsion from the University. Be sure you understand
what you are and what you are not permitted to do in regards to
academic integrity when it comes to project assignments. These
policies apply to all students, and the Student Honor Council does not
consider lack of knowledge of the policies to be a defense for
violating them. Full information is found in the course
syllabus---please review it at this time.