Table of contents
1.
Introduction
2.
Directory Structure
3.
Frequently Asked Questions
4.
Key Takeaways
Last Updated: Mar 27, 2024

Directory Structure

Author Abhay Trivedi
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

When we use the Rails helper script to create our application, it makes the entire directory structure for the application. Rails know where to find things it needs within this structure, so you don't have to provide any input. Every Rails project will have the same directory structure and naming conventions except for minor changes between releases. This consistency gives you a tremendous advantage as you can quickly move between projects without relearning the directory structure again. You can make a directory structure using a simple helper command rails demo.

Directory Structure

We can see the directory structure of ruby on rails as below.

 

Given below are the function of some of the files/folders mentioned above:

File or Folder Description

app

It works like the remainder of this directory. It organizes our application component and holds MVC.

app/assets

This folder contains static files required for the application's front-end grouped into folders based on their type.

app/controllers

It contains all the controller files. A controller handles all the web-related requests from the user.

app/helpers

It includes all the helper functions to assist the MVC.

app/mailers

It includes email-specific functions for the application.

app/models

It includes the models and data stored in our application's database.

app/views

This folder holds the display templates to fill data in our application.

bin

It contains a Rails script that starts your app. It can also include other scripts used to set up, upgrade or run the app.

config

It contains information configuring our application's database, routes, and more.

db

It includes our current database schema and database migrations.

lib

It includes an extended module for your application.

log

It has application log files.

public

It contains static files and compiled assets. It is the only folder seen by the outer world.

test

It includes unit tests, other test apparatus, and fixtures.

tmp

It includes temporary files like cache and pid files.

vendor

It includes all third-party code like vendor gems.

Gemfile

Here all your applications’ gem dependencies are declared. It is a mandatory file as it includes Rails core gems, among other gems.

Gemfile.lock

It holds a gems dependency tree, including all versions for the app.

README.md

It is a brief instruction manual of your application.

Rakefile

It finds and loads tasks that can run from the command line.

config.ru

Rack configuration for Rack-based servers used to start the application.

 

Frequently Asked Questions

1. What is a Directory Structure?

A directory structure is how an operating system arranges files accessible to the user. It displays the Files typically in a hierarchical tree structure.

2. What is a gem in Ruby?

A gem is equivalent to a plugin or an extension for the programming language ruby. They are open-source libraries containing Ruby code and packaged with extra data. To be exact even rails are nothing more than a gem.

3. Is it mandatory to follow Ruby on Rails Directory Structure?

Ruby on Rails is a full-fledged web framework written in Ruby, which has a consistent directory structure everywhere. It is less cumbersome to learn its directory structure and use it everywhere than to use your own every time. But if you wish to do it, you can do it for sure.

4. What Is the Purpose of a Directory?

We use a directory to store, organize, and separate files and directories on a computer. For example, you could have a guide to store pictures and another manual to store all your documents. By keeping specific files in a folder, you could quickly get to the kind of file you wanted to view. In short, if only pictures were in a pictures directory, it's easier to find it there than in a directory containing all types of files.

Key Takeaways

In this article, we learn a directory structure and how it is consistent across every Ruby on Rails application. We saw why it could be very beneficial for a developer. Click here to learn more about Why you should consider Ruby on Rails for your next web development project.

Click here to see other related blocks on Ruby on Rails.

You can also consider our Online Coding Courses such as the DSA in PythonC++ DSA CourseDSA in Java Course to give your career an edge over others.

If you are preparing for your DSA interviews then, Coding Ninjas Studio is a one-stop destination. This platform will help you acquire effective coding techniques and overview student interview experience in various product-based companies.

Happy Learning!

By Abhay Trivedi

Live masterclass