A guide to understanding Ruby on Rails directory structure
There is a default directory structure that Ruby on Rails comes with. The Rails guides go in depth in explaining the folder structure, but does not talk about the extra folders that commonly get added in Rails Apps.
The goal of this guide is to be a central place to learn about ALL the folders that are used in Rails apps, not just the ones that come by default (Marked with asterisk).
We will also go over explaining RSpec folder structure and any additional folders.
It organizes your application components. It's got subdirectories that hold the views, controllers, models, and more that handle business logic.
App cells are simple ruby classes that can render templates.
Contains channels used to setup connections with ActionCable.
Contains app controllers.
App decorators is a design pattern to remove view methods from models.
The Draper Gem is a popular choice to use to help with creating and using decorators.
Form Object is a design pattern that encapsulates logic related to validating and persisting data. Using these can improve the way you implement complex forms.
Contains app helpers.
Simple form allows you to create custom input components and you can place them here.
Contains app jobs.
Contains app mailers.
Contains app models.
Performers is another design pattern to abstract view methods from the model using modules.
Policies are plain old ruby objects that handle presentation logic.
Presenters is another design pattern to abstract view methods from the model using PORO.
Contains app services. A service object implements the user’s interactions with the application. It contains business logic that describe the connections with your domain objects.
A uploader is a class that is used by CarrierWave gem to model an uploaded file.
Use Cases is pretty much the same thing as services. They are designed to break up non-trivial business logic.
Value objects are an abstraction where equality is based on internal fields instead of identity.
Contains app views.
Workers are objects that allow you to run processes in the background. Remeber, it is recommended to use active job instead of your own workers so you can later switch out job runners without having to worry about api differences.
Contains the rails script that starts your app and can contain other scripts you use to setup, update, deploy or run your application.
Configure your application's routes, database, and more. This is covered in more detail in Configuring Rails Applications.
Contains your current database schema, as well as the database migrations.
Extended modules for your application.
Application log files.
The only folder seen by the world as-is. Contains static files and compiled assets.
Unit tests, fixtures, and other test apparatus. These are covered in Testing Rails Applications.
Alternative to test directory using BDD. Rspec allows you to write an alternative syntax to Test Unit that reads more like a specification than a test.
Temporary files (like cache and pid files).
A place for all third-party code. In a typical Rails application this includes vendored gems.