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 serverrails 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.
A dependency
You want a gem for star ratings: add it to the
Gemfile, runbundle 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.
Where does config/routes.rb sit, and why there?
Which file lists the gems your app depends on?
A static terms.pdf that never changes should be placed in which folder?
What does rails new bookclub use as the database unless you pass a flag?
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.
