RoR, Ruby on Rails, was officially released in 2004 by David Hansson. Rails is a library or gem that was created using the Ruby programing language. Rails gained a lot of popularity and still now used by many big companies such as Square, Twitter, GitHub, and more. It was first created to serve the web development market. However, now it is used on different platforms.
Ruby primarily was created to enhance the programmer's experience in building applications. It was built to make their lives easier and happier. Additionally, David Hansson had the same purpose while creating Rails. He saw a lot of repetitive work in developing web applications. Rails has many benefits for developers and for the development’s lifecycle. Here are some of those benefits that you can consider before choosing another language.
One Command to Build the Backend Skeleton
When you install rails on your system, you are only one command away from building the basic infrastructure for your backend. For instance, the command rails new post will create a rails application named Post in a post directory. This directory will have sub-directories that will contain the work you will do. Some of these are app, config, and db directories. Most of your work will be done in the app directory which includes but is not limited to the models, views, and controllers(MVC). Here is a snippet of a post directory.
One last thing about
$ rails newcommand, there are some flags you can add to your rails new command that customizes your project to serve your needs. For example, if you are creating an API only application, you can add a flag to the end of the new command like this:
$ rails new app --api
Model-View-Controller (MVC) Design Pattern
The MVC design pattern is one of the best things that happened to Application developments. It basically divides the application into three connected surfaces/layers.
In every application, there is data that is being stored in the database. The Model hosts code that has access directly to this data which means the Model is the only place where the actual creation, reading, updating, deleting (CRUD) of any data occurs. The View, from its name, is responsible for presenting the data to the client. Finally, the Controller is the middle layer where it connects the other two layers. It receives different kinds of requests from the browser and then talks to the model to full fill this request.
In this architecture, it is very easy to organize the different parts of your application.
Easy to Handle Modifications
In Rails, it is easy to make either a small or big change in your application. For example, let’s say you created a social networking application and you realized you needed to add another model, perhaps location, to your schema. All you need to do is to know the attributes of this model. So to add a Location model you only need to run the following command in your terminal:
$ rails generate resource Location zip_code:string city:string state:string country:string
This will create a few things:
- A Location model that inherits all the Active Records methods,
- A Location controller, where you need to add all the CRUD methods to it,
- A Location migration that has a structure of your data that will be created after you run the migrate command
$ rails db:migratewhich will migrate changes to the database.
- A Location route to the new model which is added to your routes file.
Rails has built-in security which is enabled by default. However, there are a lot of free plugins/gems you can add to your application that offer higher-level security to your application. For example, if you want to create a User model that has a password attribute, you can make use of the devise gem which will handle many user authentication activities. You can read more about it here
A lot of Support
Rails is one of the most popular languages on GitHub. It has a large community of engineers that are continually enhancing code and helping others in their projects. Also, there are plenty of Plugins/Gems that you can take advantage of and save yourself a lot of work.
I hope this blog post convinced you to give Ruby on Rails a try. Leave a comment below if you have any other reasons to use Rails.