Rails, The Ruby “magic”

June Kang
4 min readDec 21, 2020

If you’re reading this and wondering which computer language might be easiest to start, then Ruby is the language for you. Ruby is a computer language that is user friendly and gives beginner coders a basic understanding of the syntaxes(grammar of computer languages) that they need to learn. Within the Ruby language, there is a very special web framework called “Ruby on Rails”. This web framework not only makes the job of the programmer much easier, but also is convenient enough to give you the basic layouts to set up a website.

Is Ruby on Rails dying: Myth or Reality? | Hacker Noon

Rails was built by a programmer named David Heinemeier Hansson (DHH for short) in 2003. He wanted to create a framework that programmers can easily create using minimal amount of work. Rails was first used by Twitter in the beginning and from 2005 to present it has been gaining popularity by other big companies such as Github, Groupon, Airbnb, Hulu, etc. It gained enough popularity to be integrated into the mac ios system “Leopard” in 2006. This led to rails being updated constantly and is currently on version 6.0, which was released in 2019.

The two main functionality that makes Rails “magical” are: MVC structure and Convention over configuration. The MVC acronym stands for Model, View, and Controller. These three structure separate the application and have different functions.

  1. MVC structure

Model is where the object class is defined and where it holds all the logic behind some of the methods that are applied to the objects. Model communicates with the database and it also contains the relationship between each of the object classes. Meaning that an object can have many other objects or it can belong to another. These types of associations allow us to access methods that Ruby applications provide us within the model classes.

View is where we want the user to see and allow us to use the logic methods and the association we’ve created in the model by rendering it in a html(another type of computer language) format. You can also create methods in the view templates, but it is best practice to keep all the methods within the model structure.

Controller is the middleman that manages between model and view. Controller receives request from the user and decide what to render within the view structure. A model and view CANNOT communicate with each other without the controller, everything must go through the controller in order for the website to be running properly.

2. Convention over configuration

In Rails, the most of the codes that we write can be assumed because Rails doesn’t care about how keys or values are written. It is smart enough to know that once you write a singular form of an object, it also recognizes the plural form as well. That is the beauty of Rails “magic”. The program allows you to write less codes to let you further develop your website and encourages you to do it in a certain way.

By convention over configuration, you are following DRY principle. DRY is a software principle which means, Don’t Repeat Yourself. By following this principle, you maintain readable codes, have the ability to extend the codes, and you have less chance of the application being bugged.

Although Rails makes your life easier as a programmer, there are some downsides. Its not flexible, since Rails wants you to do things in a certain way. It restricts us from achieving our application in our own way. The runtime tends to be slower than other programs as well. But as we, humans, understand that we’re not perfect, we also have to understand that Rails is not perfect. There maybe updates in the future that would allow us to bypass these restrictive routes and be able to create something even better than what we can create with the current Rails.

--

--