Ruby on Rails Module 1
Rails foundations interview questions
Interview questions on rails foundations: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher
Name, in order, what a request passes in a Rails app between Puma and your controller action.
-
Fresher
A new teammate clones the Kaksha repository. What does bin/setup do for them, and why is it better than a list of steps in the README?
Answered in the lesson Install Rails 8.1 and create your first app
-
Fresher
What does bin/rails generate model Teacher name:string! email_address:string!:uniq write, and what do the two modifiers do?
Answered in the lesson The Rails command line, console and generators
-
Fresher
Why does a Rails app need no require lines for its own models and controllers?
Answered in the lesson Conventions, autoloading and Zeitwerk
-
Fresher
A page returns 500 in development. Where do you look first, and in which order?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Fresher to mid
A new Rails 8.1 app goes live behind a load balancer that polls /up. Any Host header reaches the app. Which part of the request path should refuse unknown hosts, why is it missing from the production stack, and how do you switch it on without breaking the health check?
- What it tests
- Reading the middleware stack: what ActionDispatch::HostAuthorization does, the production defaults of a new app, and keeping a health check out of a rule that covers every request.
- First step
- Run bin/rails middleware in production and look for ActionDispatch::HostAuthorization; it is not there. Then read the end of config/environments/production.rb, where config.hosts and config.host_authorization are written out and commented.
- Follow-ups
-
- Why does development have the host check when production does not?
- The load balancer calls /up with an IP address as the host. What happens once hosts are set?
- How do you test the rule before you deploy it?
From the lesson How Rails handles a request
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A coaching centre wants one product with logins for teachers and guardians, batches and attendance in related tables, fee reminders sent every evening and pages that work well on cheap phones. Would you build it on Rails or on Next.js? Defend the choice, and say what would change your mind.
- What it tests
- Choosing a framework from requirements: what each one includes, what the team would add or build instead, and what that costs over the life of the product.
- First step
- List the parts the product needs (accounts, a relational database with migrations, server-rendered pages, a job that runs every evening, email or messages) and mark for each framework which parts it includes and which the team would choose, wire up and keep working.
- Follow-ups
-
- The team writes TypeScript every day and no Ruby. Does that change the choice?
- A mobile app will need a JSON API next year. How does each option handle that?
- How would you prove the pages are fast enough on a cheap phone before you commit?
From the lesson How Rails handles a request
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Five developers and the CI server must run the same Ruby and the same Rails, and a new hire must have both on the first day. How do you pin each version, and how do you catch a computer that drifts?
- What it tests
- Version pinning in a Rails project: .ruby-version and version managers, the Gemfile and Gemfile.lock, and a check in CI that fails when a version differs.
- First step
- Name the file that decides each version: .ruby-version for Ruby (read by a version manager; mise reads it once idiomatic version files are enabled for Ruby), the rails line of the Gemfile for the allowed range and Gemfile.lock for the exact release. Then decide which command fails loudly when a computer does not match.
- Follow-ups
-
- Why does an app commit Gemfile.lock when a gem library often does not?
- How do you move the whole team from Rails 8.1.4 to the next patch release?
- CI runs another Ruby than the laptops. Where does that show up first?
From the lesson Install Rails 8.1 and create your first app
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
Kaksha starts with one coaching centre and may grow to hundreds. One teammate wants to keep the default SQLite in production, another wants PostgreSQL from day one. Which would you choose, and what would make you switch?
- What it tests
- Choosing a production database from the workload: SQLite's single writer and single-server file against a client-server database, what Rails 8's defaults keep in SQLite, and the cost of switching later.
- First step
- Write down the workload first: how many app servers, how many writes a second at the busiest hour (attendance at the start of classes), and whether anything outside the app must reach the database. Then check each against how SQLite and PostgreSQL handle it.
- Follow-ups
-
- What does a new Rails 8.1 app keep in SQLite besides its own tables?
- If you start on SQLite, how do you move to PostgreSQL later?
- What would you measure before deciding?
From the lesson Install Rails 8.1 and create your first app
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
You scaffolded batches for Kaksha and every page works on your laptop. Before teachers and guardians use it, what do you change in the generated code, and in which order?
- What it tests
- Reading generated code critically: access rules, input handling, the database constraints behind the form, the views' markup and the tests a scaffold leaves thin.
- First step
- Read the controller action by action and ask who may call each one; then read the migration and the form and ask which rules the database should enforce, before you change how the pages look.
- Follow-ups
-
- Which of the seven actions would a guardian ever need?
- The scaffold already uses params.expect. Is input handling done?
- What tests would you add before the first real user?
From the lesson The Rails command line, console and generators
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
An import stored 2,000 students' fees in rupees instead of paise, so every fee is 100 times too small. How do you fix the production data safely, and why not by typing in the production console?
- What it tests
- Running a one-off data change: where the code lives, how it is tested and rehearsed, how it runs in batches and can be repeated, and how you prove the result.
- First step
- Write the fix as code in the repository, a Rake task or a runner script, that selects exactly the affected rows (by import batch, not by guessing from the amount) and can run twice without doubling a fee.
- Follow-ups
-
- How do you make the fix safe to run twice?
- How do you rehearse it before production?
- What do you record so the change can be explained later?
From the lesson The Rails command line, console and generators
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A deploy fails at boot with Zeitwerk::NameError for app/models/sms_sender.rb, yet every page worked in development and the tests passed on laptops. Explain why, fix it, and stop it from happening again.
- What it tests
- Autoloading against eager loading, reading a Zeitwerk error, the two ways to fix an acronym, and checks that make CI behave like production.
- First step
- Read the error: it names the file and the constant its path promises. Compare that with what the file defines, then ask why development never loaded the file while production did.
- Follow-ups
-
- Why did the tests on laptops not catch it?
- Rename the class or add an inflection? What does each change?
- Which check would you add to CI, and what does it cost?
From the lesson Conventions, autoloading and Zeitwerk
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
An initializer stores FeePlan.default_paise in a setting so that every request can read it. It fails at boot in Rails 8.1. Why does Rails refuse it, what is the right place for that code, and what would go wrong if Rails allowed it?
- What it tests
- The boot sequence and reloading: why initializers cannot use reloadable constants, to_prepare against load hooks, and stale class objects in development.
- First step
- Separate the two things the line does: it reads a class from app/, which Zeitwerk manages and may reload, and it stores the result once, at boot. Then ask what that stored value is after you edit fee_plan.rb.
- Follow-ups
-
- What is the difference between to_prepare and ActiveSupport.on_load?
- The value must be read on every request anyway. Is a setting the right home for it?
- Where would you put a class that really must exist at boot and never reload?
From the lesson Conventions, autoloading and Zeitwerk
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
Some guardians get a 500 on their batch page in production, most do not, and nobody can reproduce it on a laptop. The log shows ActionView::Template::Error (undefined method 'strftime' for nil) at app/views/batches/show.html.erb:7, the line that prints the batch's start date. How do you find the cause and fix it?
- What it tests
- Debugging from production evidence: following failing requests by their request id, reading a template error and its cause, data that exists only in production, and fixing the rows and the schema as well as the code.
- First step
- Pull the lines of two or three failing requests by their request ids and compare their Parameters: which batches fail, and what do they share? Then look at one failing batch and one working batch with a read-only query before changing any code.
- Follow-ups
-
- Why does nobody see it on a laptop?
- In what order do the code, the old rows and the schema change, and why?
- How do you notice this kind of crash before a guardian reports it?
From the lesson Debugging Rails apps
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
An audit finds guardians' mobile numbers and a few access codes in Kaksha's production logs, although filter_parameters is in place. Where can such data enter a Rails log, and how do you close each way in?
- What it tests
- What parameter filtering covers and what it does not: names outside the list, values in paths, SQL at debug level, hand-written log lines, job arguments and exception messages; and how to test the fix.
- First step
- Search the logs for one leaked number and read the lines that contain it: a Parameters line, a Started path, a SQL statement or a message your own code wrote. Each kind of line has a different fix.
- Follow-ups
-
- Why did filter_parameters not hide the mobile numbers?
- The access code appears in the Started line. What changes?
- How do you keep it from coming back?
From the lesson Debugging Rails apps
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
All Ruby on Rails interview questions · The Ruby on Rails track