INF 102 Winter 2006 Teacher: Prof. Cristina V. Lopes T.A. : Trung C. Ngo ----------------------------------------------------------- hw5: Having fun with Ruby On Rails ----------------------------------------------------------- In this homework, you are asked to finish a simple web application using Ruby On Rails framework (or Rails for short) (http://www.rubyonrails.org/). Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern. Rails works with a wealth of web servers and databases. or database, you can use MySQL, PostgreSQL, SQLite, Oracle, SQL Server, DB2, or Firebird. For web server, you can install Apache, lighttpd, or even simple ruby-based web server come in rails. REQUIREMENTS: -------------- Here the list of technologies required for this homework - Ruby (http://www.ruby-lang.org/en/) - Rails frame work ((http://www.rubyonrails.org/) - SQLite (http://www.sqlite.org/) Very light and simple SQL engine that supports most standard SQL features. It distribution has two files 1) a .dll for binding with Ruby, 2) a commandline tool for administrating SQLite database INSTALL: -------- If you want to play with those technologies, download and try to install them yourself. If you don't have time, you can use the INF102 prepacked ruby/rails/sqlite distribution. It can be downloaded from here: http://mondego.calit2.uci.edu:3000/download/ruby-sqllite-pack.zip 1) unzip the package to a folder. For example: c:\opt\ruby 2) Put your ruby\bin to your environment PATH variable 3) Run the web server: Assume that you are the root folder of hw4 At command line ----------------------------------------------- c:\hw4>ruby>ruby script\server => Booting WEBrick... => Rails application started on http://0.0.0.0:3000 => Ctrl-C to shutdown server; call with --help for options [2006-02-09 18:57:32] INFO WEBrick 1.3.1 [2006-02-09 18:57:32] INFO ruby 1.8.2 (2004-12-25) [i386-mswin32] [2006-02-09 18:57:32] INFO WEBrick::HTTPServer#start: pid=5972 port=3000 ----------------------------------------------- 4) View the website Open the following URL in a web browser http://localhost:3000/index.html NOTES: the port might be different (e.g., 3001, 3002, ...) FAQ --- What does it mean to createthe following environment variables....? Creating environment variables means that you setup some variables that can be used by different programs. A commonly used variable in Windows is PATH. Windows need to use PATH variable to resolve program names if you want to use a program that is not in the current working directory. How can I set up environment variables in Windows? You can create environment variable by: 1. Go to Control Panel\System 2. Click on Advance tab 3. Click on Environment variables 4. Click on New on "System variables" list to add new system variables 5. Close all dos command prompts (if you have any opened) 6. Open new dos command prompt and type "ruby -?". If you see some response from Ruby, you are ready to go Where can I find Ruby & Rails tutorials? - http://www.rubycentral.com/book/ This site have a good ebook on Ruby programming language - http://www.rubyonrails.org/. - http://www.rubyonrails.org/screencasts This site have many nice screencasts & presentations for how to use rails. Particularly, I enjoy "Creating a weblog in 15 minutes". You should be able to learn the magic of Rails through this screencast. - http://rails.homelinux.org/ "Four days on Rails" - excellent tutorial. This tutorial teaches you how to write real web applications with Rails What IDE should I use for Rails? - highlt recommend this : http://www.radrails.org/ - nice IDE + builtin webBrick server for Rails HW5: ----- In this homework, you are requirement to finish a web application. The final system should look like the following: http://mondego.calit2.uci.edu:3000/index.html In short, this website have two functional areas - Admin Area - Customers: listing/create/edit customer records - Products: listing/create/edit product records - Categories: listing/create/edit product category records - Countries: list/create/edit country records - Customer Area - Product Catalog: list of products that are for sale - user can add a product to the shopping cart - Shopping Cart: - view the list of currently selected products - user can remove a product from the cart - user can clear the cart NOTES: the checkout feature is NOT implemented. QUESTIONS: ---------- 1) In your initial codebase, the code for listing/create/edit product categories was stripped out entirely. (goto http://mondego.calit2.uci.edu:3000/index.html, click on the "Categories" link under Admin area). You job is to implement this feature from scratch. 2) your job is to find and implement all #TODO tags in the ruby files (.rb) and tags in the .rhtml files. hw4/models/customer.rb hw4/helpers/cart_helper.rb hw4/controllers/cart_controller.rb hw4/controllers/shopping_controller.rb hw4/shopping/list.rhtml hw4/cart/list.rhtml FINAL DISTRIBUTION ------------------- - a zip file of your web system. I should be able to run the submision AS-IS - a README.txt file describes what much you have accomplished in this homework. HINTS ---------- - figure out how to generate "model" using "ruby script/generate model ...." - figure out how to generate "controller" using "ruby script/generate controller ...." - understand what is "scaffold" in Rails - the database schema is defined in sql\setupdb.sql. This file is already completed. You don't have to modify it. Tips & Tricks: -------------- - In order to reset the database to its original state, run hw4\sql\setupdb.bat - you can use the sqlite3.exe tool to view physical data stored in hw4/sql4/inf102db.db