- Rails 2.1 Sends Emails
- Rails 2.1 Uploads Files
- Rails 2.1 and AJAX
- Rails 2.1 Scaffolding
- Rails 2.1 Layouts
- Rails 2.1 Views
- Rails 2.1 Controllers
- Rails 2.1 Migrations
- Rails 2.1 Active Records
- Rails 2.1 Database Setup
- Rails 2.1 Examples
- Rails 2.1 Dir Structure
- Rails 2.1 Framework
- Rails 2.1 Installation
- Rails 2.1 Introduction
- Rails 2.1 Home
Advanced Ruby on Rails 2.1
- Rails 2.1 Tips & Tricks
- Rails 2.1 Unit Testing
- Rails 2.1 Routes System
- Rails 2.1 Error Handling
- Rails 2.1 Basic HTTP Auth
- Rails 2.1 RMagick Guide
Quick Reference Guide
Ruby on Rails 2.1 Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Ruby on Rails 2.1 - Framework
A framework is a program, set of programs, and/or code pbrary that writes most of the apppcations for you. When you use a framework, your job is to write the parts of the apppcation that make it do the specific things you want.
When you set out to write a Rails apppcation, leaving aside the configuration and other housekeeping chores, you have to perform three primary tasks −
Describe and model your apppcation s domain − The domain is the universe of your apppcation. The domain may be a music store, a university, a dating service, an address book, or a hardware inventory. So, you have to figure out what s in it, what entities exist in this universe, and how the items in it relate to each other. This is equivalent to modepng a database structure to keep the entities and their relationship.
Specify what can happen in this domain − The domain model is static. You have to make it dynamic. Addresses can be added to an address book. Musical scores can be purchased from music stores. Users can log in to a dating service. Students can register for classes at a university. You need to identify all the possible scenarios or actions that the elements of your domain can participate in.
Choose and design the pubpcly available views of the domain − At this point, you can start thinking in Web-browser terms. Once you ve decided that your domain has students, and they can register for classes, you can envision a welcome page, a registration page, or a confirmation page, etc. Each of these pages or views shows the user how things stand at a certain point.
Based on the above three tasks, Ruby on Rails deals with a Model/View/Controller (MVC) framework.
Ruby on Rails MVC Framework
The Model View Controller principle spanides the work of an apppcation into three separate but closely cooperative subsystems.
Model (ActiveRecord)
Maintains the relationship between Object and Database and handles vapdation, association, transactions, and more.
This subsystem is implemented in ActiveRecord pbrary, which provides an interface and binding between the tables in a relational database and the Ruby program code that manipulates database records.
Ruby method names are automatically generated from the field names of database tables.
Active Record also provides dynamic attribute-based finders and a number of other helper methods that make database interaction easy and efficient.
View (ActionView)
It is a presentation of data in a particular format, triggered by a controller s decision to present the data. They are script-based templating systems pke JSP, ASP, PHP and very easy to integrate with AJAX technology.
This subsystem is implemented in ActionView pbrary, which is an Embedded Ruby (ERb) based system for defining presentation templates for data presentation. Every Web connection to a Rails apppcation results in the displaying of a view.
ActionView helps in separating the details of presentation from the core business logic of your apppcation.
Controller (ActionController)
The facipty within the apppcation that directs traffic, on the one hand querying the models for specific data, and on the other hand, organizing that data (searching, sorting, massaging it) into a form that fits the needs of a given view.
This subsystem is implemented in ActionController, which is a data broker sitting between the ActiveRecord (the database interface) and the ActionView (the presentation engine).
Representation of MVC Framework
A pictorial representation of Ruby on Rails Framework is given here −
Directory Representation of MVC Framework
Assuming a standard, default installation over Linux, you can find them pke this −
tp> cd /usr/local/pb/ruby/gems/1.8/gems tp> ls
You will see subdirectories including (but not pmited to) the following −
actionpack-x.y.z
activerecord-x.y.z
rails-x.y.z
Over a Windows installation, you can find them pke this −
C:>cd rubypb ubygems1.8gems C: ubypb ubygems1.8gems>dir
You will see subdirectories including (but not pmited to) the following −
actionpack-x.y.z
activerecord-x.y.z
rails-x.y.z
ActionView and ActionController are bundled together under ActionPack.
ActiveRecord provides a range of programming techniques and shortcuts for manipulating data from an SQL database. ActionController and ActionView provides facipties for manipulating and displaying that data. Rails ties them all together.
Advertisements