CMSC 330, Fall 2009

Organization of Programming Languages

Project 7 - Ruby on Rails Web Database

Due Dec 15th, 2009


In this project, you will practice with server-side scripting using a mixture of markup (HTML, XML) and scripting (eRuby) languages.

Note this project is NOT worth any points, and is entirely for fun (even though it is scored on the submit server).

Getting Started

  • 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 appropriate scripts.
    • 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 , 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)

Project Description

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

  1. Double click on C:\InstantRails-2.0-win\InstantRails.exe to bring up the Instant Rails console.

  2. 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.

  3. In the Rails Applications console, click on "Create New Rails App..." button to bring up a command shell in the directory C:\...\rails_apps.
  4. In the command shell, type "rails guests". This will set up a number of scripts in a "guests" subdirectory.
  5. In the command shell, type "cd guests"
  6. 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.
  7. 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).
  8. In the Rails Applications console, click on "Refresh List" button. "Guest" should now appear in the list of Rails Applications.
  9. In the Rails Applications console, click on the checkbox next to "guest".
  10. 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.
  11. Now bring up your web browser and type in the URL http://localhost:3000/messages. If everything worked properly, this should bring you to the default web interface for the guest comment database:

    Listing messages

    Name Comment

    New message

  12. 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.
  13. 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.
  1. 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!.
  2. 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.
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.

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):

    Name Comment
    Hillary Hillary for president
    Barack Change we can believe in
    McCain Courageous service

  • Original Output: Should resemble the following:

    Listing messages

    Name Comment
    Hillary Hillary for president Show Edit Destroy
    Barack Change we can believe in Show Edit Destroy
    McCain Courageous service Show Edit Destroy

    New message

  • Desired Output: Should resemble the following:

    Listing messages

    Name Comment
    Barack Change we can believe in Show Edit Destroy
    Hillary Hillary for president Show Edit Destroy
    McCain Courageous service Show Edit Destroy

    New message


        <mesg>Change we can believe in</mesg>
        <mesg>Hillary for president</mesg>
        <mesg>Courageous service</mesg>


You can submit your project in two ways:
  • Submit your file index.html.erb directly to the submit server 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 7

Academic Integrity

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.