Comprehensive Rails File System Guide, Part 1 of 2
Before we go into coding. it's important to know the Rails file system. Here is a broad overview of the directories and folders that you're going to work with in any Ruby on Rails application.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
Video locked
This video is viewable to users with a Bottega Bootcamp license

Before we go into coding. it's important to know the Rails file system. Here is a broad overview of the directories and folders that you're going to work with in any Ruby on Rails application.

app directory

This directory contains the following folders:

assets This folder contains images, javascripts and stylesheets

controllers This folder controls the code flow of the application, and this is where you will run basic database queries. This is also the place where your views will look, to know what to display.

helpers You can put in this folder any custom methods that you want your views to have access to.

mailers If you want your application to send any emails, this is where the logic for it will be stored.

models This is where you will keep the most complex aspects of your application like your algorithms.

views This folder has all your html code, layouts and anything else that the user sees. By default, this folder has a application.html.erb file, and it contains all the information you need to call other pages.

This is what this file looks like:

large

The most important thing to learn now is the yield method that you see in the middle. Whatever page that needs to be called will be within this method, so you don't have to put in a head and body tag in every page. This helps to avoid code duplications and makes your application run faster.

The stylesheet tag brings in your stylesheet and the javascript tag gets the JavaScript file for you respectively.

bin directory

This file is for the application, and you're not going to use it for anything in this course.

config directory

You will be working in this directory quite often to customize your application. It contains the following folders:

environments - This folder contains all your different development environments

initializers - This folders contains all your initialization files that run when your application starts up. Specifically, it has:

assets.rb

backtrace_silencers.rb

cookie_serializer.rb

filter_parameter_logging.rb

inflections.rb

mime_types.rb

session_store.rb

wrap_parameters.rb

Out of these default files, you are more likely to use only the assets.rb to manage your assets (stylesheet routing and things like this).

Other than these files, an example of a file I would add to the initializers directory would be an email connector if I want to connect to an email API every time the server starts. Essentially this directory is for custom application configuration files that you want to load every time the application server starts up.

locales - If you want your application to use other languages besides English, you can add them here. You can also put translations in this folder and the application will use them dynamically when needed.

Other than folders, the config directory also contains the following files:

application.rb - This is your main application file and this is where you put things like any dependencies that you want to load or you can set the default time zone and locale for your application here.

boot.rb - You will use this file too, and I will give you the details later.

database.yml - When we ran the rake db:create command, this file was created. It contains the database that you will be using and other related parameters. You won't have to edit this file much.

environment.rb - This file contains details about your environment, and you won't be using this at all in this course.

routes.rb - This is another file that we will be using a lot, and I'll explain as we go.