Why I fell in love with Ruby on Rails

ruby on railsSoftware development has become indispensable. It is almost impossible to think of a company or product that does not have some kind of development work.

Under this trend, come many programming languages and frameworks for development. I will not enter in the debate of what framework is better than another. Instead, I will talk about why I fell in love with Ruby on Rails.

The Language

Ruby is a beautiful language and totally centralized, according to its creator Matz. It has great productivity and developers are happy with it. I will not get into details, but you better watch this code:

Now some rails

Is it not beautiful?

Rails console

The Rails console helps in your application before running in the browser. This makes debugging much easier. The above code, for example, I can copy and paste the Rails console and run it there.

Generators

RoR includes a set of commands that work directly on the terminal. Some of them are the generators. They help you to generate code for yourself. For example, if you want to create a controller:

Unlike that if it is created manually, this will not only make the controller; but it will generate the skeleton (with index, new, update, and create methods) the views of the routes, the assets and the necessary tests. The available generators can get it running rails generate (or rails g which is an alias).

Migrations

One of the most difficult things to do when working with medium to large applications is to change the engine in the databases. This is because there is no standard in the queries. So that queries for creating tables, inserts, selects, etc., are not the same in different engines to serve this migration.

When the migration is created, a file is generated in Ruby to make changes in the database. Which makes Rails internally  convert that code into Ruby code of SQL engine. This means that changing of engine and generate the structure of the database with its tables is as easy as changing a line of code: Change MySQL by PostgreSQL.

ORM

Rails contain an ORM that lets you forget the tedious queries. In the past, if you wanted to change your database engine you had to change the queries as well. To counteract this, Ruby has the ActiveRecord, which maps all fields of your tables to your models and lets you do something like this:

Or you can do it in less code (one line):

Convention Over Configuration

This is a basic principle of RoR that forces you to focus on what matters. This approach is much more productivity. So that you don’t have to mess with configurations.

You can see a clear example of this when you generate a model in Rails. The code looks like this:

That is a model. Internally Rails knows that this class should be linked to a table in the database called people (the plural of the model name). Likewise, you can apply any method of ActiveRecord: find, where, select, last, first, etc.

There are many other things that I like about RoR, and I could not write about all of them.

WBD Team

Our excellent WBD team working day and night to put together best content for you.

You may also like...