Rails Conventions
Fast recall
Quick revision
Core answer
Product model maps to a plural products table; ProductsController lives in app/controllers/products_controller.rb; conventional resource actions have known names; and autoloadable constant names match file paths. Rails also encourages DRY, but conventions are defaults rather than laws—override them deliberately when an external schema or clearer domain model requires it.Whether you know the naming alignment (Post model -> posts table -> PostsController -> app/views/posts/) and snake_case-file-matches-CamelCase-class.
Naming a controller PostsController but a folder app/views/post/ (singular breaks the convention), or a table post instead of posts.
Convention over configuration: Post model -> app/models/post.rb -> posts table; PostsController -> app/views/posts/. snake_case files match CamelCase classes; Rails finds everything.
Interview-ready guide
Interview answer
Rails follows convention over configuration: it assumes common names, locations, and request patterns, so an application configures mainly the exceptions. These shared defaults let developers and framework tools find a model, controller, route, view, or test without learning a private map for every project.
For a product resource, the singular Product class belongs in app/models/product.rb and normally maps to the plural products table. ProductsController belongs in app/controllers/products_controller.rb, while resources :products creates familiar routes and action names such as index, show, create, and update.
The example contains no table-name or controller-path configuration. Active Record infers products, the route DSL registers the product resource, and the controller calls the model through its public query API. Following the naming contract is what makes that small amount of code sufficient.
Zeitwerk also expects a constant path to match its file path, so Billing::Invoice belongs in billing/invoice.rb under an autoload root. Conventions are defaults, not laws: a legacy table can use self.table_name, but every override adds project knowledge. DRY means one clear source of truth, not forcing unrelated cases into one abstraction.
Rails Conventions
Direct Answer
Rails uses conventions as shared defaults so common application structure needs little configuration. A singular Product model maps to a plural products table; ProductsController lives in app/controllers/products_controller.rb; conventional resource actions have known names; and autoloadable constant names match file paths. Rails also encourages DRY, but conventions are defaults rather than laws—override them deliberately when an external schema or clearer domain model requires it.
Deep Dive & Architecture
A Rails convention is valuable because several components agree on it. Given Product, Active Record can infer products, routing can expose product resources, controllers and views can follow predictable paths, and generators can create matching tests and migrations. One name drives a connected set of defaults.
Zeitwerk-based autoloading relies on file paths matching constant paths in autoload directories. A file named app/models/billing/invoice.rb should define Billing::Invoice. A mismatch is not cosmetic—it means the loader cannot reliably connect the file to the constant.
REST conventions similarly connect HTTP intent to actions and helpers. Teams recognise what articles_path, ArticlesController#create, and app/views/articles/new.html.erb are for without inventing new vocabulary for every resource.
Configuration remains available for real exceptions, such as self.table_name for a legacy table. The cost is that each exception becomes knowledge the team must document and remember, so convention should be the baseline and overrides should solve a concrete incompatibility.
Code Example
# app/models/product.rb
class Product < ApplicationRecord
end
# app/controllers/products_controller.rb
class ProductsController < ApplicationController
def index
@products = Product.all
end
end
# config/routes.rb
# resources :products
# Product maps to the products table by convention.
Common Mistakes & Pitfalls
Naming a controller PostsController but a folder app/views/post/ (singular breaks the convention), or a table post instead of posts.
Check your understanding
Answer these without looking back at the article.
- How does a Rails model name map to its table name?
- Why must autoloaded file paths match constant names?
- When is overriding a Rails convention justified?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.