📚 Scripting Languages Tutorial

Scripting Languages

Learn scripting languages (Ruby, Perl, TCL and Tk) with simple explanations, examples, techniques and practical notes.

← Back to Scripting Languages

Rails

Ruby on Rails, commonly called Rails, is an open-source web application framework developed using the Ruby programming language.

Rails provides a collection of tools, libraries, and predefined structures that help developers create web applications quickly and easily.

Ruby is a programming language, whereas Rails is a framework that uses Ruby to develop web applications.

Rails was created by David Heinemeier Hansson (DHH) and released in 2004.

Example applications: E-commerce websites, blogs, student management systems, online booking systems, and content management systems.

Features of Rails

The following are the important features of Rails:

  1. Open Source: Rails is freely available, and developers can use and modify its source code.
  2. MVC Architecture: Rails follows the Model–View–Controller architecture to organize application code.
  3. Convention over Configuration: Rails provides standard naming rules and directory structures, reducing the need for manual configuration.
  4. DRY Principle: DRY stands for Don't Repeat Yourself. It encourages programmers to avoid writing the same code repeatedly.
  5. Database Support: Rails supports databases such as SQLite, MySQL, and PostgreSQL.
  6. Code Reusability: Developers can reuse existing code and components.
  7. Rapid Development: Rails provides built-in tools that make application development faster.
  8. Security: Rails provides built-in mechanisms to help protect applications against common web security threats.

MVC Architecture in Rails

MVC stands for Model–View–Controller. It is a software architecture used to divide an application into three main components. Those are

  1. Model
  2. View
  3. Controller

Model-View-Controller architecture: the user interacts with the View, the Controller processes requests and asks the Model for data, and the Model fetches it from the database
Fig: Model-View-Controller Architecture

1. Model

The Model is responsible for performing data validation and implementing business logic in the application. It manages application data, handles database operations and communicates with the database to store, retrieve, update and delete information.

2. View

The View represents the user interface of the application and is responsible for displaying content to the user. It generally contains HTML code along with embedded Ruby code to dynamically generate web pages.

3. Controller

The Controller is responsible for handling requests received from users and processing them accordingly. It communicates with the Model to retrieve, update or manage application data and selects the appropriate View to display the results to the user.

Working of MVC Architecture

Example: Consider a student checking their details on a website.

  1. The user sends a request through the browser.
  2. The Controller receives the request.
  3. The Controller communicates with the Model.
  4. The Model retrieves student information from the database.
  5. The Controller sends the information to the View.
  6. The View displays the student details in the browser.