Ruby on Rails RoR

Ruby on Rails RoR

Ruby on Rails (RoR)

Ruby on Rails, also known as RoR or Rails web framework is a free written in Ruby. It follows the design pattern Model-View-Controller MVC also appointed. It lets you create web applications quickly, because it imposes a structure to the programmer, and thus requires it to be a logic and approach that supports the achievement of the application. It also adds a great level of abstraction in programming the application, through a set of high level functions to focus primarily on functionality rather than the mechanics around these features.

Ruby on Rails – Philosophy

Rails is based on two fundamental principles:

“Do not repeat”

Try as much as possible to have elements of the application to a single location. The MVC architecture and meta programming in Ruby makes this possible.

Convention over configuration

It is unnecessary to specify details of where they comply with established conventions. Rails exploits this by providing default behavior for most of its features. This vision will be preserved even after the merger with Merb and future modularization framework.

When starting a project Rails, some configuration elements are present. Generally found that as the login / password to access the database in MySQL (essential example). However, we can start a project without configure anything, with the use (by default) SQLite. The configuration files are YAML type.

The first version of Ruby on Rails date of July 2004. The framework was extracted from Basecamp, a project management tool developed by David Heinemeier Hansson. The first stable version (1.0) was released December 14, 2005.

From that time Ruby on Rails has marked the world of web development. It was seen pushing a set of Rails-like Web Framework (include CakePHP, Symfony and CodeIgniter just for the PHP)

A preview release of version 2.0 was announced September 30, 2007. Rails 2.0 brings mainly:

  • The resources that provide a REST architecture;
  • A clearer differentiation between formats and converters (a. Rhtml file becomes .Html.erb, that is to say a file and interpreted by eRuby whose result is the HTML);
  • The ability to use models such as URL (e.g., redirect_to (person));
  • Management of basic HTTP authentication;
  • Protection against CSRF attacks;
  • Interception simplest generic exceptions;
  • Cache the result of some SQL queries;
  • Simplification of the writing of migration;
  • Navigation through all the plugins and modules * act_as_ database owners;
  • The beginning of the abandonment of SOAP in favor of REST;
  • A new system that replaces the debug breakpoints;
  • And many other small changes.

The latest version, 2.3.5 Ruby on Rails (RoR) was released November 30, 2009. Rails 2.3 makes use of middleware, Rack: who can manage server-level applications, and incorporates a reverse proxy. Another important change is the management of child forms from a parent object (nested form).

Rails-3 is in fact the meeting between Rails and Merb. Following a complete rewrite, agnostic (the API is generally disconnected from a particular library). A beta release dated February 5, 2010.

Architecture Model-View-Controller

Rails provides tools to build an MVC architecture:

  • Models are classes for managing data. In general the structure of these classes is determined automatically by Rails from a database. Relationships between tables are explicitly specified (has_many belongs_to). Specifying these relationships allows ActiveRecord to preload elements or parent child classes.
  • The views determine how information is displayed to the user. It is usually a combination of HTML and Ruby files. Html.erb. It is also possible to program in Ruby with pure Builder. Finally there are a multitude of plugins writing systems of basic HTML, the best known is the HAML.
  • The controllers respond to user actions, they will find the data in the database and make them available to views.

Rails to quickly create skeletons of a controller or a model or view: This is usually code type scaffolding (or scaffold) that provide common operations on the model such as adding, modifying and deleting records. These bits of initial codes are perfectly adaptable to the specific needs of the application.

Rails ActionMailer also provides for the management of sending or receiving emails and ActionWebService for SOAP and XML-RPC, and ActiveRessource to query RESTful Web service type.

Ruby on Rails – Rails and Ajax

AJAX allows for dynamic pages with JavaScript and XML to send requests to the server without reloading the page in the browser. Rails offers several ways to simplify the use of AJAX. The contribution of RJS is to allow the generation of javascript code intended for the browser through online ruby.

Ruby on Rails – Web server

Rails can work with WEBrick, the HTTP server included with Ruby. This method is often used for development and testing. In production, Apache or lighttpd or Mongrel with nginx or thin are recommended.

The use of FastCGI is not recommended from the release 2.3. In fact, the original library mod_ruby Apache has been reworked, and the interface now uses Apache Passenger. Passenger is also available for nginx.

Ruby on Rails – Managing email (sending and receiving)

The emails are generated at the views. We can create a view in text format and view HTML, sent in the same mail. The management of attachment is also supported and easy to use.

Regarding the management of incoming mail, it is possible to create a virtual user in postfix or sendmail. But the easiest is to control a mailbox via IMAP with the native ruby library. The management of incoming mail attachments using the same principle that generated emails.

ActionMailer API

Ruby on Rails – Databases

Several management systems database are supported: SQLite, MySQL, PostgreSQL, DB2, Oracle and Microsoft SQL Server. By default, SQLite3 is used.

Ruby on Rails – Distribution

Ruby on Rails is distributed through RubyGems: gem install rails. The source code is also available via GIT.

Instant Rails distribution proposes a pre-configured version for Microsoft Windows Ruby, Rails, Apache and MySQL. The proposed locomotive provides a simplified installation for Mac OS X. But Ruby on Rails (RoR) is included in the client and server versions of Mac OS X 10.5. Ruby on Rails is also included in many Linux distributions.

Ruby on Rails – Publishers

The text editor TextMate is used (in Mac OS X) by the core developers of Ruby on Rails. Alternatively and more recently Aptana IDE also offers useful features for developing and debugging Ruby on Rails. 3rdRail IDE CodeGear is for Ruby on Rails. Plugins for the Vim text editor can add useful features to develop in Ruby on Rails. There is also a mode for the Emacs editor.

Study: From Wikipedia, the free encyclopedia. The text is available under the Creative Commons.

About The Author: Santosh

Santosh is an experienced content writer with good search engine optimisation skills. Santosh works with our marketing department in the creation of articles and how-to guides for our company blog and knowledgebase.

Leave your comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.