Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

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.

15 questions: 5 warm-ups and 10 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    Name, in order, what a request passes in a Rails app between Puma and your controller action.

    Answered in the lesson How Rails handles a request

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

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

  4. Fresher

    Why does a Rails app need no require lines for its own models and controllers?

    Answered in the lesson Conventions, autoloading and Zeitwerk

  5. Fresher

    A page returns 500 in development. Where do you look first, and in which order?

    Answered in the lesson Debugging Rails apps

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

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

    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.

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

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

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

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

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

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

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

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

    From the lesson Debugging Rails apps

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  10. 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

    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

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.