95-733 Internet Technologies Homework 3 Fall 2010 Due: Wednesday October 11, 2010 Ruby on Rails =========== The goal of this project is to expose the student to the Ruby programming language and the Rails framework. Rails is based on the model, view, controller (MVC) architecture. You will write a mashup application designed to help users search for available jobs. The user will be able to enter RSS URL's as well a brief description of their sources. A relational database (sqlite3) will be used to hold these URL and source description pairs. The database will be persistent and will maintain a list of sources and associated URL's. It will be maintained (CRUD operations) via a browser using the application generated by Rails. Using the database and the database operations, the user will be able to configure the system to choose what job feeds interest them. Two controllers will be used. The first controller will allow the user to perform the CRUD (Create, Read, Update, and Delete) operations on the database. This part is a very common activity and will largely be generated by the Rails framework. This is the administrative piece of the application. Different users may be interested in different RSS feeds. The second controller will handle request by users to fetch a particular RSS feed and generate an HTML presentation. Initially, the user will only see a list of RSS sources. These source will be retrieved from the database. The user will select a source and visit the second controller. The second controller will perform a lookup in the database (by talking to the model) and find the URL associated with the source. The URL will be dereferenced and the RSS will be parsed. A view will be selected and the user will see an HTML presentation of the RSS. This HTML presentation will allow the user to select a link and visit another server where more can be learned about the job or job news. The top scores (in the A+ range) will be reserved for those projects that include cascading style sheets and Ajax. I recommend, but do not require, that you use command line tools rather than an IDE for this project. On a PC, the best approach is probably to use Instant Rails as found here: http://instantrails.rubyforge.org/wiki/wiki.pl?Getting_Started For learning Ruby, I recommend the following site: http://www.ruby-lang.org/en/ For learning Rails, I recommend the following site: http://rubyonrails.org/ For parsing the RSS XML, I recommend using a ruby gem described here: http://snippets.aktagon.com/snippets/158-Parsing-feeds-with-Ruby-and-the-FeedTools-gem Or, if that gem does not work on your installation, try the simple rss gem here: http://simple-rss.rubyforge.org/ Getting started ============================== # Build a new directory called Rails_Examples. # Inside the directory Rails_Examples, do the # following: # Check the rails version. $rails -v Rails 2.3.5 # Create a new rails application that uses the sqlite3 database. $rails -d sqlite3 CoolRSSJobApp $cd CoolRSSJobApp # Creates the CoolRSSJobApp/config/database.yml that describes the # three databases (testing, development and production). $rake db:create:all # Create the model (models/job.rb) , migration script, # database table maintenance controller (controllers/jobs_controller.rb). # Under views/jobs, this command creates CRUD views .html.erb files. $ruby script/generate scaffold Job source:string url:string # Create the actual database. $rake db:migrate # Run the server and visit the CRUD application. $ruby script/server =>Booting Mongrel =>Rails 2.3.5 application starting # The controller is called jobs_controller.rb. There # is a method in the controller # called index. There is an index.html.erb in # app/views/jobs. # Visit the index method with a browser at : http://localhost:3000/jobs # You can perform CRUD operations on the new database. # Experiment! Study the directories, controller and views. # Add a new controller called main_controller.rb. $ruby script/generate controller main # Add a method to main controller. class MainController < ApplicationController def welcome @num_sources = Job.count end end # Create a partial HTML file called welcome.html.erb. # This files needs to reside in the # CoolRSSJobApp/app/views/main directory. # Ruby automatically includes the HTML tags.

Welcome to the Job Seeker Application

We currently have <%= @num_sources %> sources. # Notice how the view is able to extract # information from the instance variables in # the controller. # Vist with: http://localhost:3000/main/welcome # If this does not work, try stopping and then restarting # the server. # Note the controller file is named main_controller.rb. # The method within # the controller is named welcome. The file named welcome.html.erb # is in app/views/main. The HTML file is delivered to the user # after the welcome method is run. # If you want to visit with http://localhost:3000/main/ # then you need to add an index method to the main controller # and an index.html.erb to the app/views/main directory.