skip to content

Project Anatomy & Startup

How a Rails app is created, laid out and started: rails new options, directory and naming conventions, boot, Zeitwerk autoloading and upgrades. Interviewers use it to test real project experience.

part ofRuby on Railsread it →
on this pageshow

explore

questions

page 1 of 2

In a Rails 8.1 app, why does an edited model take effect without a restart in development but not in production?

level: juniorimportance: must knowfreq 55%

answer

  1. two settings per environment
  2. enable_reloading: true only in development
  3. eager_load: true only in production
  4. test eager loads when CI is set
  5. reload! in the console

basics

~20 s

Development sets config.enable_reloading = true, so after a file changes Rails unloads autoloaded application constants before the next request, which autoloads fresh code. Production sets enable_reloading = false and eager_load = true, loading all code once at boot.

solid answer

~40 s

Two settings in `config/environments/*.rb` decide it. `config.enable_reloading` is `true` in the generated `development.rb` and `false` in `test.rb` and `production.rb`; `config.cache_classes` is its older inverse spelling. With reloading on, a file watcher notices a change in the autoload paths, and before the next request Rails unloads the constants the main Zeitwerk loader autoloaded, so the request autoloads the edited code. `config.eager_load` is `false` in development, `true` in production and `ENV["CI"].present?` in test, so production loads every file at boot and never reloads. In `bin/rails console` no watcher runs; `reload!` reloads by hand. Reloading covers only autoloaded code: initializers, `config/application.rb` and gems still need a restart.

code

ruby · 11 lines
ruby
# config/environments/development.rb (generated)
Rails.application.configure do
  config.enable_reloading = true
  config.eager_load = false
end

# config/environments/production.rb (generated)
Rails.application.configure do
  config.enable_reloading = false
  config.eager_load = true
end

go deeper

for a junior

Remember the two switches and their values per environment, and that the console needs reload! after an edit.

for a middle

Explain the reload cycle: file watcher, unloading the main autoloader's constants before the next request, autoloading fresh code; and what never reloads.

for a senior

Justify eager loading in production by boot-time errors and copy-on-write memory, and know where rake_eager_load and the CI switch change that picture.

for a principal

Weigh development speed against fidelity: when to eager load in CI or locally to catch loading bugs that lazy loading hides.

## Two settings, three environments Whether edited code shows up without a restart is decided by two settings that every generated `config/environments/*.rb` file spells out: | Setting | development | test | production | |---|---|---|---| | `config.enable_reloading` | `true` | `false` | `false` | | `config.eager_load` | `false` | `ENV["CI"].present?` | `true` | - **`config.enable_reloading`** decides whether application constants can be unloaded and loaded again while the process runs. `config.cache_classes` is the older name with the opposite meaning (`cache_classes == !enable_reloading`) and is still accepted. - **`config.eager_load`** decides whether all code in the eager-load paths is loaded at boot, instead of lazily on first reference. ## What a reload does in development With reloading enabled, Rails configures the main Zeitwerk loader (`Rails.autoloaders.main`) with reloading on. A request cycle looks like this: 1. A file watcher tracks the autoload paths. The default class is `ActiveSupport::FileUpdateChecker`; `ActiveSupport::EventedFileUpdateChecker` is the alternative and needs the `listen` gem. 2. When a watched file changed, Rails unloads every constant the main loader autoloaded **before the next request is processed**. Unloading means removing the constant, as `remove_const` does; Ruby cannot patch a class in place everywhere it is referenced. 3. The request then references `Filing` again, Zeitwerk autoloads `app/models/filing.rb` afresh and the new code runs. Because `config.reload_classes_only_on_change` is `true` by default, nothing is unloaded when no file changed. ## Why production does the opposite Production sets `enable_reloading = false` and `eager_load = true`: - **Everything is loaded at boot.** Requests do not pay for autoloading application code, and memory loaded before a server forks its workers can be shared copy-on-write. - **Errors surface at boot.** A file that defines the wrong constant raises `Zeitwerk::NameError` during the deploy rather than on some later request. An edit to a deployed file therefore needs a new process: a deploy or a restart. ## The console and Rake tasks - **Console:** no file watcher runs in `bin/rails console`, whatever `enable_reloading` says, so a session keeps a consistent set of classes. Call `reload!` to reload by hand; objects built before it still belong to the old class objects. - **Rake tasks:** while a Rake task runs, `config.eager_load` is replaced by `config.rake_eager_load`, which is `false` by default. Production Rake tasks therefore load lazily. ## What reloading never covers Reloading only touches constants that the **main** autoloader manages. These need a restart even in development: - `config/application.rb`, `config/environments/*.rb` and `config/initializers/*.rb`, which run once at boot; - gems and the Gemfile; - code in `config.autoload_once_paths` (or `lib` set up with `config.autoload_lib_once`), which is autoloaded but deliberately not reloaded; - a brand-new top-level directory under `app`, because the autoload paths are fixed at boot. ## When an edit does not show up A short checklist for the common "I changed it and nothing happened" report in development: 1. **Is the code autoloaded?** Only files under the autoload paths are reloaded. Code in an initializer, in `config/application.rb`, in a gem, or in a file loaded with `require` needs a restart. 2. **Is it in the autoload once paths?** Classes in `config.autoload_once_paths`, or in `lib` when the app uses `config.autoload_lib_once`, are autoloaded but never reloaded, on purpose. 3. **Did something capture the old class?** A registry, a constant or a framework setting filled at boot keeps the class object from boot; reloading creates a new one that nobody stored. 4. **Is it the console?** `bin/rails console` never reloads on its own; run `reload!` and rebuild the objects you are holding. 5. **Is reloading on at all?** Check that `config.enable_reloading` is still `true` in `config/environments/development.rb`; an old app may still say `config.cache_classes = false`, which means the same thing. ## Test environment `test.rb` disables reloading because a test run is a single pass. It eager loads only when the `CI` variable is set, so local runs boot quickly while CI loads every file and catches naming errors.

  • Why does a long-open bin/rails console not see an edit to app/models/filing.rb?
    No file watcher runs in the console, regardless of `config.enable_reloading`, so a session keeps one consistent set of classes. Call `reload!` to unload and reload application code. Objects you built before `reload!` still point at the old class object, so rebuild them after reloading.
  • In production, does a Rake task eager load the application?
    Not by default. While a Rake task runs, `config.eager_load` is overridden by `config.rake_eager_load`, which defaults to `false`, so tasks autoload lazily even in production. Set `config.rake_eager_load = true` if a task depends on all code being loaded.

A restaurant kitchen during prep works from loose recipe cards a cook can swap between orders; once service starts, the printed menu is fixed and changing a dish means reprinting it, which is production's restart.

  • Rails reloads every Ruby file in the project on each request in development.
  • Editing config/initializers files takes effect on the next request in development.
  • config.cache_classes = true turns reloading on.
  • Production autoloads lazily, so a misnamed file only fails when a request reaches it.
  • The Rails console reloads changed models automatically before each command.
open as a page

In a Rails 8.1 app, what do config/boot.rb, config/application.rb and config/environment.rb each do at startup?

level: juniorimportance: must knowfreq 52%

basics

~10 s

config/boot.rb makes the Gemfile's gems loadable. config/application.rb loads Rails, requires the app's gems and defines the Application class with its settings. config/environment.rb requires it and calls Rails.application.initialize!, which runs every initializer.

open as a page

What do convention over configuration and DRY mean in Rails, and which configuration does a Rails CRUD for people never write because of them?

level: juniorimportance: must knowfreq 70%

basics

~20 s

In Rails, convention over configuration means names and locations imply behaviour, and DRY means each fact lives in one place; a people CRUD declares no table mapping, columns, routes per action, template paths or form URLs, because Rails derives them.

open as a page

In a Rails genealogy app, which names does a Person model imply for its table, files, controller, routes, views and foreign keys?

level: juniorimportance: must knowfreq 80%

basics

~10 s

A Rails Person model lives in app/models/person.rb and maps to the people table; PeopleController handles resources :people, with helpers like people_path and person_path, templates under app/views/people, and other tables point at it through person_id.

open as a page

In a Rails 8.1 app, what does each folder under app/ hold, and which base classes does rails new put there?

level: juniorimportance: must knowfreq 75%

basics

~20 s

Rails 8.1's app/ is split by role: models, controllers, views, helpers, mailers, jobs, assets and javascript. rails new seeds each Ruby folder with an Application* base class, such as ApplicationRecord and ApplicationController, that the app's own classes inherit from.

open as a page

In Rails 8.1, what does a plain `rails new` app ship with for the database, JavaScript, CSS, jobs, caching and deployment?

level: juniorimportance: must knowfreq 70%

basics

~20 s

A plain Rails 8.1 rails new picks SQLite, import maps with Turbo and Stimulus, Propshaft with plain CSS, Solid Cache, Solid Queue and Solid Cable instead of Redis, Puma, and a Dockerfile with Kamal and Thruster, plus RuboCop, Brakeman and bundler-audit binstubs.

open as a page

In a Rails 8.1 app, what path does an HTTP request take from config.ru to a controller action?

level: juniorimportance: must knowfreq 62%

basics

~20 s

The Rack server loads config.ru, which boots the app and runs Rails.application. Its call(env) sends the request down the middleware stack to the router, which matches a route and dispatches to a new controller instance's action.

open as a page

In a Rails 8.1 app, how does Zeitwerk decide which constant app/services/filings/deadline_calculator.rb must define, and how do you check the whole tree?

level: middleimportance: must knowfreq 62%

basics

~10 s

Zeitwerk camelizes each path segment below an autoload path, so app/services/filings/deadline_calculator.rb must define Filings::DeadlineCalculator. bin/rails zeitwerk:check eager loads the app and names any file that defines the wrong constant.

open as a page

In Rails 8.1, how does RAILS_ENV select a config/environments file, and in what order do application.rb, that file and config/initializers apply?

level: middleimportance: must knowfreq 55%

basics

~20 s

Rails.env comes from RAILS_ENV, else RACK_ENV, else development, and only config/environments/<env>.rb is loaded. The application.rb class body runs first, then the environment file, then framework initializers, then config/initializers in sorted order; a later assignment overrides an earlier one.

open as a page

In a Rails 8.1 print-shop app, where should a class that builds PDF invoices live: app/models, a new app/services folder, or lib/?

level: middleimportance: must knowfreq 55%

basics

~20 s

Domain code goes under app/: a plain class in app/models or a role folder such as app/services or app/pdfs; lib/ is for code that is not about the print shop and could become a gem. A new app/ folder needs no configuration, only a restart.

open as a page

In a Rails app, what does config.load_defaults 8.1 do, and why does the app keep 8.0 behaviour right after bundle update rails?

level: middleimportance: must knowfreq 58%

basics

~10 s

config.load_defaults applies every framework default introduced up to that version. Upgrading the gem leaves the line at 8.0, so 8.0 defaults stay until you flip the lines in new_framework_defaults_8_1.rb and raise load_defaults to 8.1.

open as a page

In a Rails 8.1 app, what does bin/rails middleware print, and why does the order of the default stack matter?

level: middleimportance: must knowfreq 45%

basics

~20 s

bin/rails middleware prints the built stack for the current environment, outermost first, ending with run App.routes. Order matters because each middleware wraps everything below it: it decides what runs before it, what it can short-circuit and which exceptions it catches.

open as a page

In Rails, how would you upgrade a municipal-library catalogue app from 7.1 to 8.1 safely, and why one minor version at a time?

level: seniorimportance: must knowfreq 55%

basics

~20 s

Move Ruby to 3.2+ on 7.1, reach the latest 7.1 patch with no deprecation warnings, then step through 7.2, 8.0 and 8.1: bump the gem, run bin/rails app:update, fix removals, deploy, flip the new defaults, raise load_defaults.

open as a page

Outside app/, what do a Rails 8.1 app's bin/, config/, db/, lib/, script/, test/ and vendor/ hold, alongside the Gemfile and Gemfile.lock?

level: juniorimportance: should knowfreq 50%

basics

~20 s

In Rails 8.1, bin/ holds executables, config/ settings and routes, db/ migrations and schema, lib/ code outside app/ plus lib/tasks, script/ one-off scripts, test/ the test suite and vendor/ third-party code; the Gemfile declares gems and Gemfile.lock records the exact versions.

open as a page

In a Rails 8.1 app, what does the generated `bin/setup` script do, and why can you run it again safely?

level: juniorimportance: should knowfreq 45%

basics

~20 s

bin/setup installs gems, prepares the database with bin/rails db:prepare, clears logs and tmp files, then execs bin/dev; each step converges on a state rather than repeating work, so reruns are safe, and --skip-server or --reset adjust it.

open as a page

In a Rails 8.1 app, why does renaming the class in lib/docket/pdf_exporter.rb to Docket::PDFExporter break production boot with Zeitwerk::NameError?

level: middleimportance: should knowfreq 40%

basics

~10 s

config.autoload_lib puts lib in the autoload and eager-load paths, and Zeitwerk expects pdf_exporter.rb to define Docket::PdfExporter. Production eager loads at boot, finds Docket::PDFExporter instead, and raises Zeitwerk::NameError.

open as a page

In Rails 8.1, how do config.x and Rails.application.config_for differ for app-specific settings, and what does each return when a value is missing?

level: middleimportance: should knowfreq 30%

basics

~10 s

config.x holds namespaced settings assigned in Ruby, such as config.x.ticketing.currency; an unset key reads nil. config_for(:ticketing) loads config/ticketing.yml, evaluates ERB and returns the current environment's section merged over shared; a missing file raises.

open as a page

In a Rails app, what does `inflect.acronym "HTTP"` change for a file named lib/archive_http_client.rb, and what breaks if you add it late?

level: middleimportance: should knowfreq 35%

basics

~10 s

With inflect.acronym "HTTP", Rails camelizes archive_http_client to ArchiveHTTPClient instead of ArchiveHttpClient, so the file must define that constant; adding it after code uses ArchiveHttpClient breaks loading until every reference is renamed.

open as a page

In Rails, what does "fat model, skinny controller" mean, and when should a growing Person model be split up?

level: middleimportance: should knowfreq 50%

basics

~20 s

In Rails, "fat model, skinny controller" means domain rules live on models while controllers only handle params, loading records, calling one model method and rendering; when a Person model grows into a god object, extract plain classes under app/models.

open as a page

In a Rails genealogy app, what goes wrong when a Census model relies on the default English inflections, and how does inflect.irregular fix it?

level: middleimportance: should knowfreq 40%

basics

~20 s

Rails' default rules leave census unchanged when pluralizing and singularize censuses to censuse, so a Census model gets a census table, census_index route helpers and a broken has_many :censuses; inflect.irregular "census", "censuses" fixes every derived name at once.

open as a page

In a Rails 8.1 app, where does a one-off script that imports a print shop's legacy orders belong: script/, lib/tasks/ or db/migrate/?

level: middleimportance: should knowfreq 40%

basics

~10 s

A one-off import belongs in script/, for example script/import/legacy_orders.rb, which loads config/environment and runs with bin/rails runner; lib/tasks/ suits tasks you rerun by name, and db/migrate/ is for schema changes every environment must replay.

open as a page

For a Rails 8.1 greenhouse dashboard on PostgreSQL with Tailwind and no inbound email, which `rails new` flags fit, and what does each change?

level: middleimportance: should knowfreq 50%

basics

~10 s

Run rails new greenhouse -d postgresql -c tailwind --skip-action-mailbox: the pg gem and a PostgreSQL database.yml replace SQLite, tailwindcss-rails adds Tailwind without Node, and Action Mailbox's engine is commented out while outgoing mail stays.

open as a page

In Rails 8.1, what does `rails new --minimal` strip from a new app, what does it keep, and how do you bring one piece back?

level: middleimportance: should knowfreq 40%

basics

~20 s

In Rails 8.1, --minimal implies about twenty --skip-* flags, removing jobs, mailers, storage, Cable, Hotwire, JavaScript, Solid, Kamal, Docker and the lint and audit tools, while keeping Active Record, Propshaft, Puma and Minitest; --no-skip-active-job restores one piece.

open as a page

How does Rails number its releases, and how long does a minor series such as 8.1 get bug fixes and security fixes?

level: middleimportance: should knowfreq 38%

basics

~20 s

Rails uses a shifted semver: minors may break APIs after a deprecation, patches only fix bugs, and a fourth digit marks a security release. A minor series gets bug fixes for one year and security fixes for two years from its first release.

open as a page

In a Rails 8.1 app, config/initializers/exporters.rb registers ClauseRenderer from app/renderers in a registry; why does boot raise NameError, and what goes stale once it is forced to work?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Initializers run before Rails sets up the main autoloader, so reloadable app classes cannot be referenced there. If forced in, the registry keeps the class object from boot, and after a reload it holds a stale class.

open as a page

In Rails 8.1, when do before_initialize, to_prepare and after_initialize blocks run, and which suits code that configures a reloadable class?

level: seniorimportance: should knowfreq 40%

basics

~20 s

before_initialize runs at the end of bootstrap, before framework and app initializers. to_prepare runs once at boot, before eager loading, and again after every code reload. after_initialize runs last, once. Code that configures a reloadable class belongs in to_prepare.

open as a page

In a Rails 8.1 museum-ticketing app, config/initializers/booking_limits.rb reads a flag set in feature_flags.rb and sees nil; why, and how would you fix it?

level: seniorimportance: should knowfreq 35%

basics

~20 s

Files in config/initializers load in sorted path order, so booking_limits.rb runs before feature_flags.rb, and config.x returns nil for a key nobody has set yet. Set the flag in application.rb or the environment file, or read it later.

open as a page

In the Rails Doctrine, what do the menu is omakase, provide sharp knives and the majestic monolith mean, and where do they show in Rails 8.1?

level: seniorimportance: should knowfreq 30%

basics

~20 s

The Rails Doctrine's omakase pillar means Rails picks a full default stack; sharp knives means it hands developers powerful tools and trusts them; the majestic monolith means one integrated app. Rails 8.1 shows all three in its generator defaults and APIs.

open as a page

In a containerised Rails 8.1 app, which of storage/, tmp/, log/ and public/assets must survive a redeploy, and which can be thrown away or rebuilt?

level: seniorimportance: should knowfreq 30%

basics

~10 s

In a Rails 8.1 container, storage/ must persist on a volume because it holds the SQLite databases and Disk-service uploads; tmp/ and log/ are disposable; public/assets is rebuilt by assets:precompile during the image build.

open as a page

In a Rails 8.1 app, what do the generated `bin/rubocop` and `bin/bundler-audit` scripts run, and how do you handle a gem advisory that does not apply?

level: seniorimportance: should knowfreq 30%

basics

~10 s

bin/rubocop runs RuboCop with an explicit --config .rubocop.yml that inherits rubocop-rails-omakase; bin/bundler-audit checks Gemfile.lock against ruby-advisory-db using config/bundler-audit.yml, whose ignore: list holds advisory IDs you have reviewed and accepted.

open as a page

showing 1–30 of 36