Ruby on Rails Introduction
Lecture Notes for CS349W
Fall Quarter 2008
John Ousterhout
- Probably the most high-level Web application framework.
- 2 components:
- Ruby programming language: dynamic and object-oriented.
(won't cover in detail in this class)
- Rails framework: set of Ruby classes for creating Web applications.
- Rails applications have an MVC (model-view-controller) structure:
- Model: manages the application data via ORM
- Each class encapsulates the data in a particular database table.
- View: templates that generate Web pages.
- Controller: glue between the model and view:
- Responds to incoming HTTP requests
- Fetches/modifies data in the models
- Invokes a view to generate the Web page
- The MVC pattern has been around since the late 1970's; originally
conceived in the Smalltalk project at Xerox PARC.
- Key element of Rails framework: "convention over configuration":
- Many conventions for how you should structure your applications
(e.g., directory structure for files)
- Tools implement many of the conventions automatically
- If you follow the conventions, many things happen automatically:
- If there is a database table named Employees with a column
salary, Rails will automatically define a class Employee
with an instance variable named salary; this field will be
displayed in a form element named salary for editing.
- Simplifies things greatly over other frameworks where all of the
configuration must be specified explicitly in complex XML files;
avoids cumbersome repetition (DRY).