Now that you have created your first Rails App and started looking inside the application directory we know some of you hunger for the details of all the folders and files generated. So here is a quick rundown of what in each directory. Take your time and explore away.
app
is where you'll put the majority of your application code. You'll be spending alot of time in here. Rails is very opinionated software so it place a lot of emphasis on keeping code organized, so the app directory has a number of sub-directories:
assets
contains sub-directories where you'll store your application's images, JavaScript files, and stylesheets (CSS)
channels
is where you put Ruby classes designed to handle real-time features using Action Cable
controllers
is where you will organize your Controller code (i.e. the C in mvC)
helpers
is where Ruby modules that define utility methods for views are kept
jobs
is where Ruby classes for running background jobs are kept
mailers
is where you put Ruby classes for generating and sending emails
models
is where you will organize your Model code (i.e. the M in Mvc)
views
is where you will organize your View code (i.e. the V in mVc)
bin
contains rails script files and binaries. You will not be messing around this folder.
config
is where you go to tweak the configuration settings of your application. Rails sets 'sensible defaults' for your app, so you wont initially need to edit anything in here. But later on you will use this directory to fine tune your app. Some of the more important files in here include,
database.yml
configures the database used by each environment
environments
is a directory that contains 3 files that define specific settings for each environment: development, test, and production
initializers
is a directory where you put Ruby code that needs to be run when the application starts
routes.rb
maps incoming requests (URLs) to application code
db
contains everything related to the database, including migration files and in the case of using the default SQLite3 database the database file itself.
lib
is where you put any reusable "library" code that's not a model, view, or controller. An important subdirectory is,
tasks
is where you put any custom Rake tasks for your application. Each file has a .rake extension
log
is where Rails automatically creates log files. These files keep an audit log of what happened when your app ran. Each environment gets its own log file
public
is the document "root" directory of the app. It contains static files that are served directly by the web server. For example the notorious Not found error page (404.html) lives here and gets served when a page can't be found.
test
is where you put test files if you use the default test library. This is not used by RSpec
tmp
is where Rails stores any temporary files needed by the app. You wont need to go into this directory
vendor
is more of a legacy directory where third party code used to live. Now a days we use gems instead
Gemfile
- this file contains a list of third-party dependencies (Ruby gems) that your application needs