Ruby on Rails is a framework that allows developers to create architecturally clean applications. It saves time and effort while ensuring high quality. The framework follows three major design principles which makes it one of the top choices of clients and web application developers.
Ruby on Rails Principle 1: Model-View-Controller (MVC)
Model-View-Controller was first introduced in 1979 by Treygve Reenskaug in Smalltalk-76 when he was visiting Xerox Parc. Trygve is a Norwegian computer scientist and a professor at the University of Oslo. In the 80s, Jim Althoff, with the help of others included MVC for the Small-talk 80 library. MVC was established as a general concept in The Journal of Object Technology in 1988.
The Model contains codes that work on the application data. Any command from the user must go through this layer. Modification definitions such as retrieving data, creating, updating and deleting are written here.
The View works as a visual layer for the user. It determines how user interacts with the application and how data are presented to the user.
The Controller works as the name suggests. It controls both the models and the view. It dictates the stream of data. It receives user command, works with models to process it and instructs the view to properly display to the user.
Rails structures the application in files and directories. Directories are normally located as “app” directory. It creates different sub directories where it puts files. “models” sub-directory applies specific structure on ruby files. Models are pre-determined. Developers can modify models to suit the application requirement. “controllers” directory contains ruby files that control the application. Normally, each controller is assumed to have its own presentation layer as view files. These files are stored as “views” directory according to the name of the controllers. The view files are a special type of html denoted as .html.erb that can contain embedded Ruby code.
Active Record Pattern
Active Record Pattern is an important attribute of Ruby on Rails framework. It is the “M” of the MVC principle that we mentioned earlier. Active record pattern is an architectural design pattern for data that frequently requires persistent storage in a database. Another acronym that is quite frequently mentioned alongside active record pattern is “CRUD“. It stands for Create, Read, Update and Delete. Active Record automatically creates ways for the application to read and modify data stored in the database. Active record pattern represents models and their data, inter-model association, validates models and performs database operations.
Ruby on Rails Principle 2: Conventions over Configurations
Convention over configuration is a web application development principle that aims to reduce time and effort taken by developers. It does not necessarily reduce flexibility in development. For example when there is a class “Sale” in the model, the relevant table in the database will automatically be named “Sales” unless, the developer decides to configure the name differently.
Including Ruby on Rails that Nascenia specializes on, a couple of other frameworks follow the principles such as Lift, CakePHP, Apache Maven, Grails, Symfony etc. These conventions keep the code clean and provide an easy way to navigate through the application.
Ruby on Rails Principle 3: Don’t Repeat Yourself (DRY)
Don’t Repeat Yourself is a principle that reduces the repetition of information within a complex system. Every single information should have a clear and relevant link to the rest of the system.The principle aims to reduce code repetition as much as possible so that it becomes easy to make any modification in the development cycle. The helpers and the libraries in Ruby on Rails help the code to remain “DRY”. Interestingly, the opposite of DRY is Wet development. Wet development is commonly referred to as “write everything twice” or “We Enjoy Typing”, indicating the redundancy of information within a system.
The goal of the three principles are simple: making Ruby on Rails an easy, viable and preferred framework for development. These principles bring simplicity in developing a complex system. They reduce redundancy and eventually make it one of the favorite frameworks among developers for application development. Here is beautiful quote for you before finishing the article.“Ruby on Rails is a breakthrough in lowering the barriers of entry to programming. Powerful web applications that formerly might have taken weeks or months to develop can be produced in a matter of days.” – Tim O’Reilly, Founder of O’Reilly Media Contributor: Mushtahir Aziz Rahman, Business Executive, Nascenia