DEV Community

Cover image for Rails Landmarks - Don't Get Lost!
Eisea904
Eisea904

Posted on

Rails Landmarks - Don't Get Lost!

Opening a repository that uses Ruby on Rails can be an intimidating experience to those new to the experience. There are many folder with many folders with many files. However just like moving to a new city, once familiarized with major landmarks you can begin to enjoy your drive to work and find new things to love in this new big city!

Let's take a look at the file tree to see what fun things there are in this town.

Alt Text

There's a lot here, even before expanding most of these folders. We're going to look at two groups - landmark folders in app_folder/app and landmark files outside the /app folder. We'll go over the primary function of each item. A simplified filed tree is below:

app_folder/
--> app/assets/stylesheets/
--> app/controllers/
--> app/models/
--> app/views/
app_folder/
--> config/routes.rb
--> db/
--> --> migrate/
--> --> schema.rb
--> --> seeds.rb

The app folder houses our MVC, Model View Controller folders. These are three of the most beautiful parks in the city, and powerful tools that rails gives us. Our model folder houses associations: our belongs_tos has_manys, and validateses. With this, our program can understand that a comment belongs_to :post and that a user can have_many :posts.

Controller holds the methods that each model can use. Most models (a site's users, Facebook's posts) can be created, read, updated, and destroyed (CRUD), among other capabilities like sign in. The view folder holds the .html files, literally what your audience views on the browser. There should be a folder for each model, each with a .html.erb file for every action or page you give that model. assets/stylesheets contains .css files, one for each model.

Alt Text

As you cruise through your new town you're likely to see many road signs, some with directions and arrows, others with advertisements of what is nearby. Our config/routes.rb files is where to find most or all of the arrows and paths that a user on your site with be sent down. This is where we find our verbs: get, post, patch, delete, etc. A simple tool for knowing how to write these paths is RESTular.com . Your migrate folder houses all your migrations and the schema.rb folder shows all of the elements that go into your models.

If you have children you will no doubt want to help them feel safe at home in this new town. The seeds.rb file is the backseat of your minivan, with plenty of room for all your rambunctious example material and class instances.
There is a lot to see in this new home of yours. Relax and enjoy the ride!

Top comments (0)