As amazing and magical as Rails can be, it can also be challenging to understand where to start working. and to understand the directory structure of the application.
This article will explain The directory structure rails apps.
But before we get into the directory structure of rails applications first we must have a good understanding of the
Model View Controller structure(MVC).
Let's dive in.
After Creating the application
rails new my_app
Boom! The first Rails app ready to start working on it.
cd my_app then run
code . to open the application in the code editor.
What are those files and folders that have just been created!?
Now let's explain the purpose of each one of these directories.
It organizes the application components. It has subdirectories that hold the view (views and helpers), controllers, and the backend logic (models), and here where will be most of the work done.
let's go over the app subdirectories one by one.
Channels for ActionCable, which integrates WebSockets with the rest of the Rails application. and allows real-time features to be written in Ruby.
The C in MVC. This subdirectory is where Rails looks to find the controller classes. A middle man between the model and the view.
Utility methods used to assist the model, view, and controller. This helps to keep the code small and focused.
Background jobs, The jobs can be enqueued and executed using the different queuing backend.Active Job Basics
Routers for incoming emails. This folder is not present on the app until we use the Action Mailbox feature of Rails.
Mailing structure for the app.
The M in MVC. This subdirectory holds the classes that model and wrap the data stored in our application's database.
The V in MVC. Usually written in embedded Ruby (erb), it can also be written in another templating language such as Slim or Haml.
Holds the scripts to start/manage our Rails application.
Holds the configuration files, such as database configurations, routings, localizations, etc.
Holds the migration files for the tables, schema file, and database seeders. which are just files that can be executed to prepare the database with some initial data.
Rake files and independent codes, usually libraries unless they explicitly belong elsewhere (such as vendor libraries).
Holds error logs. Rails create scripts that help us to manage various error logs. there are separate logs for the server (server.log) and each Rails environment (development.log, test.log, and production.log).
Holds the static files, such as favicon, compiled assets, error pages.
Uploaded files for disk storage.
For the test files. but since many in the community prefer to use the RSpec framework for writing test codes; in that case, this folder will be deleted.
Rails uses this directory to hold the temporary files.
Third-party front-end dependencies. (such as security libraries or database utilities beyond the basic Rails distribution).
Apart from these directories, there are some more files:
This file contains a basic detail about the application and a description of the directory structure explained above.
This file helps with building, packaging, and testing the Rails code.
Contains a list of all the gems that we want to include in the application. It is used with bundler (also a gem) to install, update, remove and manage the used gems.