How to Ruby on Rails- Directory Structure
This guide explains the default directory structure generated by Ruby on Rails. Let’s get started with the directory structure. In the last tutorial, we discussed the installation of Rails. The RailsInstaller already created an app named Todo in C:\\sites.
To create a new Rails app, open up Rail command line and run the following command:
rails new sample_app
Rails will automatically create its own directories and files.
Once Rails created the app, You will find the directory structure as follows
Let’s go through each directory and files,
app: This organizes your application components. It’s got subdirectories that hold the view, controller, and the backend business logic.
app/assets: This contains the static files required for the application’s front-end grouped into folders based on their type.
app/controllers − The ‘controllers’ directory is where Rails looks to find controller classes. A controller handles a web request from the user. Controllers are responsible for orchestrating the model and views.
app/helpers: This is where all the helper functions for views reside. There are already a few pre-created helpers available.
app/mailers: The mailers directory contains the mail (as in “email”) specific functions for the application. Mailers are similar to controllers and they will have their view files in app/views/mailer_name/
app/models: All model files live in the app/models directory. Models act as object-relational mappers to the database tables that hold the data.
app/view: The third part of the MVC architecture are the views. The files related to the views go into this directory. The files are a combination of HTML and Ruby and are organized based on the controller to which they correspond.
app/view/layouts: This folder holds the layout for all your view files, which they inherit. Files created in here are available across all the view files.
bin: This directory contains Binstubs for the Rails application. Binstubs are nothing but wrappers to run the gem executables scoped to your application.
Config: As the name suggests this contains all the application’s configuration files. The database connection and application behavior can be altered by the files inside this directory.
db: Rails application will have model objects that access relational database tables. You can manage the relational database with scripts you create and place in this directory.
Gemfile: The Gemfile is the place where all your app’s gem dependencies are declared.
Gemfile.lock: Gemfile.lock holds the gem dependency tree, including all versions, for the app.
lib: lib directory is where all the application specific libraries reside.
log: This holds all the log files. Rails automatically create files for each environment.
public: The public directory contains some of the common files for web applications.
test: The folder name says it all. This holds all the test files for the app.
tmp: This is the temporary directory for the app to hold files like caches.