95-733 Internet Technologies Homework 3 Spring 2010 Due: Tuesday April 20, 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 design pattern. 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's and source descriptions. 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. I recommend, but do not require, that you use command line tools rather than an IDE for this project. 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 An Example Ruby on Rails Application ============================== # 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 jobs $cd jobs # Creates the jobs/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. 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. $ruby script/generate controller main # Add a method to main controller. class MainController < ApplicationController def welcome @num_sources = Job.count end end # Add a partial HTML file called welcome.html.erb. # Ruby automatically includes the HTML wrapper.

Welcome to the Job Seeker Application

We currently have <%= @num_sources %> sources. # Vist with: http://localhost:3000/main/welcome # Note the controller is named main. The method within # the controller is named welcome. The file 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.