Overview of a Ruby on Rails App File System Setup
In the previous guide, we created a Rails project. What did it exactly create for us? That's what we're going to see in this lesson. If you're already familiar with Rails, this is going to be more of a review lesson for you.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

In the previous guide, we created a Rails project. What did it exactly create for us? That's what we're going to see in this lesson. If you're already familiar with Rails, this is going to be more of a review lesson for you.

To start, Rails created the following directories for us.

medium

This file setup will be similar for all Rails projects because the creators wanted to ensure come consistency when it came to file storage and access, so that the project does not depend on the knowledge of any single individual.

The app directory contains the majority of your code.

medium

Inside the assets folder is where you'll put your images, javascripts and stylesheets while the controllers folder will contain files that control your application's data flow.

The helpers folder contains files that you can call when needed to avoid cluttering your view template files. It's more like a library of files that help to perform a certain functionality. These files also make your code read better and extend the functionality of the application as a whole, as you can use them any number of times across your application.

The mailers folder contains any file or code that's going to help you to send emails.

The models folder will manage the data portion of the application, as this is where you put your custom data algorithms, relationship attributes, scopes and validators.

Lastly, the views directory will contain all the files that help to render out your application to users. All html files are created in this folder. An important file in this folder is application.html.erb. It acts as the master template for all other html files, so you don't have to repeat code on each file. You can put all the common items such as page title and headers in this master template, and it will be available to all other html files.

Besides app directory, you have bin and config directories that contain the application's configuration information. The database directory will contain anything related to the database such as you schema file, while lib directory will have all the custom rake tasks that you want to integrate with your application. The log directory will contain logs, the public directory is another place to store a few different types of files that we won't get into for this tutorial, and the test directory contains built-in test cases. Typically, I don't use this built-in test library, instead I use RSpec to test my code. The tmp directory contains caching and other temporary files, and lastly, the vendor directory is another spot for third-party assets.

Below these directories are a list of files, and out of these, you'll use the Gemfile extensively. It contains a list of all the gems that you'll integrate into your application. Gems are nothing but Ruby code that performs a certain function, and you use it to avoid writing the same code again in your application. Here's how it looks.

large

So, that's a basic introduction of how the application is setup. If you want a more detailed walk through you can go through these tutorials below: