Welcome to Rails: A guide for beginners from a beginner

SunJet Liu
3 min readOct 19, 2020

So you want to create a new rails app? Here are my cliff notes. At first you might be overwhelmed with the amount of new information, so let me break it down for you. To start you will need to focus on the following items.

-Controllers
-Models
-Views
-Routes
-Migrations

A new ruby on rails app will have many folders and files you don’t recognize but the folder(s) you need to focus on are mostly in the the “app” folder. The “app” folder will contain the “controllers”, “models” and “views” folders. The second folder you want to be familiar with is the “config” folder. Here, your “routes.rb” file can be found. Lastly the “db” folder has your “migrate” folder and your “seeds.rb” file. I will attempt to explain what each folder/file does for your app below.

“app” folder, “config” folder, and “db folder

ROUTES

Let’s start with the “config folder where your main concern is “routes.rb”. Think of routes as your linking file. How does your browser know where to go? Your “routes.rb” file is like a giant spider ”web” that connects everything. Your router will let your app know which controller and which CRUD action rails should take.

Credit: Greg @Flatiron School

CONTROLLER

The next item on the list would be controller. The controller takes the request from the router, and produces the appropriate output. The controller will receive the request, fetch or save data from a model and use a view to create HTML output. A controller is the middle man between models and views. In other words the controller will take your methods aka “actions” and use the routing that you set in “routes.rb” to get the model to give you the data you want.

MODEL

Models are the database managers. They talk to the database, hold all the table relationships, preform CRUD on the tables, and last but not least validate data which you set. This is where you create your has many, has many through, belongs to, table relationships. This is also where your app makes sure that your data is the correct type, exists, is unique, and many more.

VIEWS

Views is where you keep all your browser pages. The files in this folder usually includes all your html/ruby code to see all your different forms, photos, links, etc. you see on your webpage. This is where you will do all your formatting, styling and graphical interfaces.

MIGRATION

In the “db” folder you will have a “seeds.rb” file and a folder called “migrate” . Seeds are basically data the programmer pre programs into the database as test and fodder data. When you are programming your site a variety of example data is convenient to have for testing. The “migrate” folder will contain your files that you use to build the schema of your tables. This will tell your app what are the names and type of data each column of your table consists of. Basically the framework or skeleton of how your tables are built.

CONCLUSION

This is a very simplified explanation of what a beginner will typically need to understand when starting off in making a rails app. The MCV (Models, Controllers, Views) ideology is that a software application should be built based on dividing up responsibilities into three main areas. Your routes makes all the links and your migration creates the database/tables to hold all your data. I hope this will help you on your journey through code.

Sources and further reading: https://guides.rubyonrails.org/getting_started.html

--

--