LearnThatStack Ace your next interview
Backend Development

Ruby on Rails.

Start free Change topic Change
Practice · Questions

All questions

Showing of 70
Beginner 9
01

What is Ruby on Rails and what is the MVC pattern?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

02

Explain the Rails directory structure and purpose of key folders

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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 for models, views and controllers. helpers and assets have 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/ or spec/ holds the tests.
  • vendor/ holds third-party code.
  • Gemfile lists the gem dependencies.
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

03

What is the difference between symbols and strings in Ruby, and why does Rails prefer symbols for hash keys?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

04

What is the Rails Convention over Configuration principle?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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 User maps to the database table users.
  • The controller UsersController handles the /users routes.
  • Every primary key is named id.
  • A foreign key is the singular table name plus _id, like user_id.

Following them means less code to write, and every Rails project looks familiar to a new developer.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

05

Explain database migrations in Rails

Visual

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

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_migrations table. That gives the schema version control.
  • Teammates get new migrations with the code and run bin/rails db:migrate to catch up.
  • Rollback with bin/rails db:rollback reverts the last migration. Rails can reverse a change method by itself when every command in it is reversible, like create_table or add_column. Raw SQL and other irreversible steps need separate up and down methods.
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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

06

What's the difference between find, find_by, and where?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

find and find_by return a single record, while where returns a collection of every match, even when nothing matches.

  • find searches by primary key and raises ActiveRecord::RecordNotFound if the record is missing.
  • find_by takes any conditions and returns the first match, or nil if there is none. Its bang version, find_by!, raises instead.
  • where returns an ActiveRecord::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, not nil.
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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

07

What is the difference between render and redirect_to?

Visual

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain
Visual

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 :new shows the new template without running the new action. Instance variables from the current action, like @user with its errors, stay available to the view.
  • redirect_to @user sends 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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

08

What are the differences between rails console options?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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, or rails c, starts the standard console in the development environment.
  • rails console --sandbox starts sandbox mode, which wraps the session in a database transaction and rolls back every change when you exit.
  • rails console -e production loads the production environment, so your commands act on live data.
  • rails dbconsole, or rails db, opens the database client, such as psql, 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.

Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

09

How does Rails handle different environments and what are they used for?

Beginner ·

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:

Keep going - a few more words and AI can grade it.

Last attempt -

Your answer

Re-explain

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
Rewriting in plainer words…

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 ↓

Related concept

Tailored explanation · switch back to · ·
What should the new diagram focus on?
How well did you know this?
AI:

Intermediate 45
10

What is ActiveRecord and how does it implement the Active Record pattern?

Part of Pro
11

Explain different types of associations in Rails

Part of Pro
12

What is the N+1 query problem and how do you solve it?

Part of Pro Visual
13

What are scopes in ActiveRecord and how do you use them?

Part of Pro Visual
14

Explain callbacks in ActiveRecord and their order of execution

Part of Pro Visual
15

What are validations and how do custom validations work?

Part of Pro Visual
16

What are strong parameters and why are they important?

Part of Pro Visual
17

Explain the Rails routing system and RESTful routes

Part of Pro
18

What are before_action filters and how do they work?

Part of Pro Visual
19

How do you handle different response formats in Rails controllers?

Part of Pro
20

Explain nested routes and when to use them

Part of Pro
21

How does Rails protect against CSRF attacks?

Part of Pro Visual
22

What is SQL injection and how does Rails prevent it?

Part of Pro Visual
23

Explain Rails session management and storage options

Part of Pro Visual
24

How do you implement authentication in Rails?

Part of Pro
25

What is lazy loading vs eager loading in ActiveRecord?

Part of Pro
26

What is the Rails cache store, and what are the available options?

Part of Pro
27

Explain the Rails asset pipeline and its benefits

Part of Pro
28

What testing frameworks does Rails support and what are the differences?

Part of Pro
29

What are fixtures and factories in Rails testing?

Part of Pro
30

How do you test Rails APIs?

Part of Pro
31

What is the difference between stubs and mocks in testing?

Part of Pro
32

What is ActiveJob and what adapters does it support?

Part of Pro
33

When should you use background jobs in Rails?

Part of Pro Visual
34

How do you build RESTful APIs in Rails?

Part of Pro
35

What serializers can you use for JSON APIs in Rails?

Part of Pro
36

How do you implement API versioning in Rails?

Part of Pro
37

What are concerns in Rails and when should you use them?

Part of Pro
38

What are service objects and when should you use them?

Part of Pro
39

What are Rails generators and how do you create custom ones?

Part of Pro
40

What are the key considerations for deploying Rails applications?

Part of Pro
41

How do you manage environment-specific configuration in Rails?

Part of Pro
42

How do you implement rate limiting in Rails?

Part of Pro Visual
43

What are Turbo and Stimulus, and how do they work with Rails?

Part of Pro
44

How do you handle file uploads in Rails?

Part of Pro Visual
45

How do you debug Rails applications effectively?

Part of Pro
46

Explain the request/response cycle in Rails

Part of Pro
47

How do you implement internationalization (i18n) in Rails?

Part of Pro Visual
48

What is the difference between includes and joins?

Part of Pro Visual
49

What is a polymorphic association?

Part of Pro Visual
50

How do database transactions work in Active Record?

Part of Pro Visual
51

What is the difference between pluck and select?

Part of Pro
52

What are the security headers Rails provides and how do you configure them?

Part of Pro
53

What is ActionCable and how does it work?

Part of Pro
54

What is the difference between delegate and forwardable?

Part of Pro
Expert 16
55

What's the difference between includes, preload, and eager_load?

Part of Pro Visual
56

Explain optimistic vs pessimistic locking in Rails

Part of Pro Visual
57

Explain different caching strategies in Rails

Part of Pro Visual
58

How do you optimize database queries in Rails?

Part of Pro
59

How do you handle job failures and retries?

Part of Pro
60

How do you implement API authentication?

Part of Pro
61

Explain Rails engines and when to use them

Part of Pro
62

Explain the Rails autoloading mechanism

Part of Pro Visual
63

How do you handle multi-tenancy in Rails?

Part of Pro
64

Explain monkey patching in Rails and its risks

Part of Pro
65

What is the difference between Webpacker, Sprockets, and Import Maps?

Part of Pro
66

Explain database connection pooling in Rails

Part of Pro Visual
67

What are the benefits and implementation of database sharding in Rails?

Part of Pro Visual
68

What is Rack middleware and how do you create custom middleware?

Part of Pro Visual
69

What are the best practices for Rails application security?

Part of Pro
70

How do you run schema migrations without downtime?

Part of Pro Visual

No matches

Try a different filter or search term.

Know someone prepping for Ruby on Rails? Send them this set.
Quick recap

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.

Get Pro · $10/mo
Pro · $10/mo

61 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.

Technologies
No technologies match “”.
Cross-cutting topics
No topics match “”.
By role
Stacks & frameworks

MEAN

MongoDB, Express, Angular, Node.js

MERN

MongoDB, Express, React, Node.js

LAMP

Linux, Apache, MySQL, PHP

Django

Python Full-Stack Development

Ruby on Rails

Convention over Configuration

Serverless on AWS

Serverless Architecture on AWS

Flutter Mobile

Flutter Cross-Platform Mobile Development

Spring Boot

Enterprise Java Development

.NET

Microsoft Ecosystem

Vue

Vue.js, Vite, TypeScript, Tailwind, Node.js

Go Backend

Golang, gRPC, PostgreSQL, Redis, RabbitMQ

FastAPI

Python, FastAPI, SQLAlchemy, PostgreSQL

React Native

React, TypeScript, Redux, Firebase

iOS Native

Swift, SwiftUI, UIKit, Firebase

Android Native

Java, Jetpack Compose, Firebase

DevOps / Platform

Docker, Kubernetes, Terraform, CI/CD

AI Engineer

LLMs, RAG, Agents, Evals

AI-Powered Developer

Claude Code, Copilot, Agentic Workflows

Core SWE Interview Prep

Data structures, algorithms, OS, concurrency, networking, git