Do you know David Heinemeier Hansson, the creator of ruby on rails is a race driver😲? Interestingly, David has participated in 98 races winning 10 out of 98.
It is apparent David is familiar with voyaging and journeying on a fast lane. No wonder the web framework suits the Rapid Application Development (RAD) development model perfectly.
Maybe, that’s where the concept of the name ruby on rails came from. Realizing a gem while journeying🤔? Who knows🤔? Enough of the assumptions. One fact to note is that his 41st birthday is a month exactly from today and it’s a great opportunity to appreciate Dave for the great framework he created. Moreso, making it open source.
However, it could be a scary journey while traversing around rails for the first time. For some, they begin with a false start running off rails and never coming back to the framework seeing the number of files and directories being created on running the first project setup command:
rails new [new-project]
dir*.*/s on windows for the newly created project shows that it has 8,276 directories and 16,729 files. In order not to scare you, rails also ensure this detail is encapsulated by giving you a nice directory structure such as this:
It would be nice to breakdown the structure of these files meaningfully. Wouldn’t it? Join me in this journey 🚶 on rails 🚆 as I take you through the file structure so you won’t have a false start.
Before we begin this journey, I would be giving out this basic rule. It is best to keep by this unless your journey on rails might be sloppy. It is best not to manipulate with certain files on rails if you don’t have an idea of what they do especially in production. It would even be more disastrous deleting these files. Top-of-the-list is all files in app/config directory. Just as the name goes, the config directory has all the basic configurations for your project including but not limited to environment setup, active records configurations, mailbox configurations, database setup, routing and other configurations.
Now that we know the rules, we can continue our journey on rails. Seeing a bunch of files and directories may be confusing and one good way to identify them is by the file extension type. I would be explaining some usual file extensions you would see in a rails 6 application:
This is a templating extension where you can write your HTML, js, etc. and wrap your ruby code around it. You would need this mostly in your views.
These are basically files that help manage your source code repositories and versions.
This is where gems and their versions are stored. It has a corresponding lock file that ties the dependencies to the project. Gems are simply plugins, packages, or libraries that would help you code better and lesser. Are they not gems after all?
package.json is the common culprit inheriting the .json extension. And it basically manages your dependency along with yarn.lock.
Stores your secret key such as master.key. Files with this extension are very sensitive.
This is a text file that can be formatted to suit. The most popular file with this extension is README.md where you can document steps in running your project.
For me, this is the most important file extension as it contains pure ruby code. This is the ruby file extension.
This is a ruby doc file suitable for comment management and other documentation. Rubydoc is a cool tool similar to javadoc and phpdoc.
This is used for data-serialization and database.yml uses this approach to store database information.
The beauty of ruby on rails is its graceful representation of the MVC structure. MVC helps to separate your code structure aiding for faster development and reusability. In actual fact, rails extend its separation even down to the server level where the app server runs your rails app and puts your code in memory and sends a response to the webserver which then handles the request and returns back to the app server on processing if necessary, else the webserver is self-sufficient. Common web servers for rails are nginx and apache. However, for the app server, we have puma and unicorn while passenger can act as both. The various directories and files that help to bring about a beautiful MVC structure in rails are:
As with a proper MVC secure structure, this folder is specifically set aside for files and folders that would be available to the public.
The helpers directory is where series of re-usable functions that would aid your development is contained.
This consists of your data representation. The various class building blocks, getter, and setter methods of individual data. Here, you might find database queries used to create various data dimensions.
This contains your user interface files to provide functionalities to the end-user.
This holds your business logic and does manipulations based on your application rules.
The journey to getting familiar with rails might be rough. But I can assure you it’s worth it.
Here are some reasons why:
Rails is pretty much a secure framework. I mean a lot of work has been done in making rails as secure as possible. You can read this article here:
With rails, you would be writing just little code because of its excellent file structure and plugins. You would probably be doing more architectural thinking. But I can assure you, a little code written with rails can do much more than expected.
With the “convention over configuration” vibe, easier automated testing, version control, off-the-shelf RESTful architecture, seamless separation of development environments, and for the fact ruby can be said to be “strongly typed”, you can hardly write bad code unless you want to anyway.
Some of your favorite apps built with ROR are: Ask.fm, Airbnb, Bloomberg, Dribble, Fiverr, Genius, Goodreads, Scribd, Slideshare, Shopify, and Soundcloud.
And even our darling dev.to!!!!!
Have a great journey on rails ahead!
Need help? Looking for homies? Join our Web Dev Chat with Like-minded Individuals. Everyone is welcome.
Sebastian Alsina -
Get These In Place Before Starting Your Next Side Project 👀
Niharika Singh ⛓ -
9 New best free courses selected of Udemy [Only for hours]
Pablo Álvarez Corredera -
7 DevOps Myths – Busted
Sara Miteva -