Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Meet Rails  ›  Lesson

Creating an App and Its Folders

Create an App 15 minrails new builds a complete, runnable app whose folders each have one job: app for your code, config for settings, db for the schema, bin for commands, public for static files and the Gemfile for dependencies.

Creating an App and Its Folders

One command gives you a working web app: a server that starts, a database that connects and a welcome page. The command is rails new. What it leaves behind is a set of folders, and knowing their jobs is half of knowing Rails.

The rule

Your code in app, settings in config, data shape in db.

rails new bookclub
cd bookclub
bin/rails server

rails new creates the project, writes a Gemfile and runs bundle install. bin/rails server starts the Puma web server at http://localhost:3000. The defaults in Rails 8 are SQLite for the database, Hotwire for interactivity and Importmap for JavaScript, so there is no build step to set up. Flags change the defaults, for example rails new bookclub --database=postgresql.

The folders that matter first:

Path Job
app/ Your code: models, views, controllers, helpers, javascript, assets, jobs, mailers
config/ Settings: routes.rb, database.yml, environments/, credentials
db/ migrate/ (schema changes), schema.rb (current shape), seeds.rb (starter data)
bin/ Scripts you run: bin/rails, bin/setup, bin/dev
public/ Static files served as-is, such as 404.html and robots.txt
Gemfile The gems (libraries) the app depends on; Gemfile.lock pins exact versions

You will also see test/ for tests, log/ for log files and tmp/ for caches.

The shortcut

Ask "is it code, a setting, the data's shape, a command, a static file, or a dependency?" Each answer points to exactly one place.

Adding reviews to BookclubStep 1 of 4
  1. A dependency

    You want a gem for star ratings: add it to the Gemfile, run bundle install.

Do not edit db/schema.rb by hand. It is regenerated from your migrations, so manual changes are silently lost.

Drills

Answer fast — trust the rule.

quick drill

Where does config/routes.rb sit, and why there?

quick drill

Which file lists the gems your app depends on?

quick drill

A static terms.pdf that never changes should be placed in which folder?

quick drill

What does rails new bookclub use as the database unless you pass a flag?

quick drill

Why should you not hand-edit db/schema.rb?

Remember

  • Your code in app, settings in config, data shape in db; commands in bin, static files in public, gems in the Gemfile.
  • Shortcut: classify the change, and the folder follows.
  • Trap: editing schema.rb by hand instead of writing a migration.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFind the right folder

In Bookclub you need to (1) add a gem for pagination, (2) change the database password, (3) add a Review model, (4) add a new migration and (5) drop in a static robots.txt. Say which file or folder each change goes in and why.