DEV Community

Abraão Carvalho
Abraão Carvalho

Posted on

Introduction to Ruby on Rails

What is Ruby on Rails?

Ruby on Rails is a web development framework written in the Ruby programming language. It follows the MVC (Model-View-Controller) architectural paradigm, which means it separates the business logic of data presentation and manipulation into three distinct components: Model, View, and Controller.

Model

In the Model we have the layer responsible for data manipulation. Models represent the real-world objects that your application interacts with and are typically mapped to tables in a relational database. Rails uses a library called ActiveRecord to map objects into relational databases.

View

In View we have the layer responsible for presenting data to the user. Views are typically composed of HTML code with Ruby code embeds to dynamically render data. Rails uses the ERB (Embedded Ruby) template engine for this, allowing you to write HTML with Ruby embedded.

Controller

And in the Controller, we have the layer that handles HTTP requests and decides how to respond to them. Controllers are responsible for receiving requests from the browser, interacting with models to fetch or manipulate data, and rendering the appropriate views to be sent back to the browser. They contain the actions (methods) that respond to different HTTP requests.

In addition to these three core components, Ruby on Rails also provides a number of other functionalities, including:

Routing

Rails offers a routing system that maps URLs to controller actions. This allows you to easily define your application's routes and specify which controller actions should be called for each URL.

Helpers

Helpers are auxiliary methods that can be used in views to generate HTML in an easier and cleaner way. They help keep views cleaner and more organized.

Migrations

Migrations are a way to version the database schema. They allow you to define database schema changes in Ruby files, which can be versioned along with the rest of your source code and automatically applied to the database when your application is updated.

Scaffolding

Rails offers a tool called scaffolding that can automatically generate the basic code for create, read, update, and delete (CRUD) resources. This can speed up the initial development of your application by providing a functional starting point.

Conclusion

These are just some of the main concepts and features of Ruby on Rails. Overall, Rails is designed to be a powerful and productive framework for web development, allowing developers to quickly build robust and scalable web applications.

Top comments (0)