The Ruby on Rails folder structure
When a new Ruby on Rails project is created with rails new
, many files and folders are created inside your project folder. Here’s a quick reference of what those are.
path | what it is |
---|---|
./app | 90% of your application code goes here. Your models, views, controllers, mailers, and workers (if you’re using Resque) are organized inside app . Feel free to make your own subdirectories. |
./bin | Where binstubs – gem executables wrapped for use in your app’s environment – live |
./config | Set up your database, your routes, deployment environments, i18n localization here. For all things related to configuring your app. |
./config.ru | This is the file that links Rack with Rails. |
./db | Your migrations, your schema.rb , and, if you’re using SQLite, your development.sqlite database |
./Gemfile and ./Gemfile.lock | Used by bundler to know what gems your app needs |
./lib | A wasteland that’s appended onto the load path. Except for custom rake tasks in ./lib/tasks , I’ve never seen code in lib that shouldn’t be somewhere else. Don’t put code here. |
./log | Where your log files go |
./public | Anything put here will be available to the world as http://www.myapp.com/filename . Things like 500.html go here, because this directory still works when your app crashes. You can also serve out static assets, like CSS files or images. Feel free to make subdirectories. |
./Rakefile | The Rakefile is responsible for defining all of those basic Rails tasks, like db:migrate , when you call rake from the command line. The only justified reason I’ve seen for munging this file is when you want to load in a limited subset of Rails (such as for Resque). |
./README.rdoc | The most important file in a Rails app. Use it to document how your app works, how to run it in development, etc. |
./test | The most useless folder in Rails. 99% of the time, testing is for chumps. Use your limited time in life to do something meaningful. |
./tmp | A toiletbowl for precompiled assets, pid files, and session files. Don’t put anything permanent here, because the toilet flushes. |
./vendor | 3rd party code, like gems not managed by bundle or CSS libraries |