All questions
Showing of 70What is Ruby on Rails and what is the MVC pattern?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Ruby on Rails is a server-side web framework written in Ruby. It organizes an app with the Model-View-Controller (MVC) pattern, which has three parts.
- The model holds the data and business logic, and talks to the database through Active Record.
- The view is the presentation layer, usually HTML built from Embedded Ruby (ERB) templates.
- The controller receives each request, asks the models for data and picks the view.
Rails also follows convention over configuration, so common tasks need little setup. Don't Repeat Yourself (DRY) keeps each piece of logic in one place, which makes code easier to maintain.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the Rails directory structure and purpose of key folders
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
rails new generates the same directory structure for every app, so developers know where code lives. The key folders are:
app/holds the application code, with subfolders formodels,viewsandcontrollers.helpersandassetshave their own subfolders there too.config/holds the configuration, such as routes and database settings.db/holds the database schema, the migrations and the seed data.lib/holds your own modules and libraries.public/holds static files that the web server serves directly.test/orspec/holds the tests.vendor/holds third-party code.Gemfilelists the gem dependencies.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between symbols and strings in Ruby, and why does Rails prefer symbols for hash keys?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A symbol is an immutable name that Ruby stores only once, while a string is mutable text, and each "name" literal creates a new object. So every :name in a program is the same object.
That makes symbols a good fit for hash keys and other identifiers:
- They save memory, because every use of a key shares one object.
- Comparing two symbols only checks that they are the same object, which is faster than comparing strings character by character.
- They cannot change, so a key cannot be modified by accident.
# Symbol - same object_id
:name.object_id == :name.object_id # true
# String - different objects
"name".object_id == "name".object_id # false
Rails uses symbols for option keys, like validates :email, presence: true. Request params accept both kinds of key, so params[:id] and params["id"] return the same value.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the Rails Convention over Configuration principle?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Convention over Configuration means Rails assumes what you want from standard names and places, so you write configuration only when you break a convention. Some of those conventions:
- The model
Usermaps to the database tableusers. - The controller
UsersControllerhandles the/usersroutes. - Every primary key is named
id. - A foreign key is the singular table name plus
_id, likeuser_id.
Following them means less code to write, and every Rails project looks familiar to a new developer.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain database migrations in Rails
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A migration is a Ruby class that changes the database schema one step at a time, so the schema evolves in a consistent way. You describe the change in a Ruby domain-specific language (DSL) instead of SQL. A migration written only in this DSL works on any database Rails supports.
- Each file name starts with a timestamp, and Rails records the ones it ran in the
schema_migrationstable. That gives the schema version control. - Teammates get new migrations with the code and run
bin/rails db:migrateto catch up. - Rollback with
bin/rails db:rollbackreverts the last migration. Rails can reverse achangemethod by itself when every command in it is reversible, likecreate_tableoradd_column. Raw SQL and other irreversible steps need separateupanddownmethods.
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :email
t.timestamps
end
end
end
Each run updates db/schema.rb, the schema snapshot used to build a fresh database.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What's the difference between find, find_by, and where?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
find and find_by return a single record, while where returns a collection of every match, even when nothing matches.
findsearches by primary key and raisesActiveRecord::RecordNotFoundif the record is missing.find_bytakes any conditions and returns the first match, ornilif there is none. Its bang version,find_by!, raises instead.wherereturns anActiveRecord::Relation. The query does not run until you use the records, so you can chain more conditions first. When nothing matches, you get an empty relation, notnil.
User.find(1) # Raises error if not found
User.find_by(email: "a@b.com") # Returns nil if not found
User.where(active: true) # Returns Relation (chainable)
Use find when the record must exist, find_by when it may not, and where when you need a set of records.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between render and redirect_to?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
render builds the response from a template within the current request, while redirect_to tells the browser to send a new request to another URL.
render :newshows thenewtemplate without running thenewaction. Instance variables from the current action, like@userwith its errors, stay available to the view.redirect_to @usersends a 302 response with the new URL. The browser then requests that page, so the target action runs from the start and the old instance variables are gone.
def create
@user = User.new(user_params)
if @user.save
redirect_to @user # New request to show action
else
render :new, status: :unprocessable_entity # Renders new template with @user errors
end
end
That gives the usual pattern for forms. After a successful save, redirect, so refreshing the page does not submit the form again. After a failed save, render the form again with status 422. Turbo, the JavaScript library new Rails apps include since Rails 7, only shows a form response that redirects or carries an error status.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the differences between rails console options?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
rails console opens an interactive Ruby session with the app loaded, and its options decide which data you touch and whether changes stay.
rails console, orrails c, starts the standard console in the development environment.rails console --sandboxstarts sandbox mode, which wraps the session in a database transaction and rolls back every change when you exit.rails console -e productionloads the production environment, so your commands act on live data.rails dbconsole, orrails db, opens the database client, such aspsql, with the app's connection settings.
# Sandbox mode - all changes rolled back
rails console --sandbox
# Production console
RAILS_ENV=production rails console
Use sandbox mode to try a risky query safely, and take extra care in a production console, where every change is real.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How does Rails handle different environments and what are they used for?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Rails runs an app in one named environment at a time, chosen by the RAILS_ENV variable, and loads that environment's settings on boot. Three come by default:
- development reloads code after every change, shows detailed error pages and includes debugging tools like the web console.
- test runs the test suite against its own database, loads fixtures and rolls back each test's changes.
- production is tuned for performance. It loads all code once at boot, turns on caching and hides error details from users, so teams add error monitoring there.
# Check current environment
Rails.env.development? # true/false
Rails.env # "development"
# Environment-specific code
if Rails.env.production?
# Production-only code
end
Each environment has its own file in config/environments/ and its own section in config/database.yml. To add a custom environment such as staging, you create both yourself.
# Custom environments
RAILS_ENV=staging rails server
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is ActiveRecord and how does it implement the Active Record pattern?
Explain different types of associations in Rails
What is the N+1 query problem and how do you solve it?
What are scopes in ActiveRecord and how do you use them?
Explain callbacks in ActiveRecord and their order of execution
What are validations and how do custom validations work?
What are strong parameters and why are they important?
Explain the Rails routing system and RESTful routes
What are before_action filters and how do they work?
How do you handle different response formats in Rails controllers?
Explain nested routes and when to use them
How does Rails protect against CSRF attacks?
What is SQL injection and how does Rails prevent it?
Explain Rails session management and storage options
How do you implement authentication in Rails?
What is lazy loading vs eager loading in ActiveRecord?
What is the Rails cache store, and what are the available options?
Explain the Rails asset pipeline and its benefits
What testing frameworks does Rails support and what are the differences?
What are fixtures and factories in Rails testing?
How do you test Rails APIs?
What is the difference between stubs and mocks in testing?
What is ActiveJob and what adapters does it support?
When should you use background jobs in Rails?
How do you build RESTful APIs in Rails?
What serializers can you use for JSON APIs in Rails?
How do you implement API versioning in Rails?
What are concerns in Rails and when should you use them?
What are service objects and when should you use them?
What are Rails generators and how do you create custom ones?
What are the key considerations for deploying Rails applications?
How do you manage environment-specific configuration in Rails?
How do you implement rate limiting in Rails?
What are Turbo and Stimulus, and how do they work with Rails?
How do you handle file uploads in Rails?
How do you debug Rails applications effectively?
Explain the request/response cycle in Rails
How do you implement internationalization (i18n) in Rails?
What is the difference between includes and joins?
What is a polymorphic association?
How do database transactions work in Active Record?
What is the difference between pluck and select?
What are the security headers Rails provides and how do you configure them?
What is ActionCable and how does it work?
What is the difference between delegate and forwardable?
What's the difference between includes, preload, and eager_load?
Explain optimistic vs pessimistic locking in Rails
Explain different caching strategies in Rails
How do you optimize database queries in Rails?
How do you handle job failures and retries?
How do you implement API authentication?
Explain Rails engines and when to use them
Explain the Rails autoloading mechanism
How do you handle multi-tenancy in Rails?
Explain monkey patching in Rails and its risks
What is the difference between Webpacker, Sprockets, and Import Maps?
Explain database connection pooling in Rails
What are the benefits and implementation of database sharding in Rails?
What is Rack middleware and how do you create custom middleware?
What are the best practices for Rails application security?
How do you run schema migrations without downtime?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
Ruby on Rails in pictures.
A quick recap of Ruby on Rails in 31 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 28 pictures come with Pro.
Ruby on Rails cheatsheet
- App layout & conventions01
- Routes & controllers02
- Models & associations03
- Queries & eager loading04
- Migrations, locks & scaling05
- Security & sign-in06
- JSON APIs07
- Jobs, caching & WebSockets08
- Hotwire, assets & uploads09
- Test, debug & deploy10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 28 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in61 of 70 Ruby on Rails answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.