71 Rails interview questions with answers
71 Rails interview questions with detailed answers, sorted from basic to advanced. Free to practice, with progress saved automatically.
All Rails interview questions
What is Ruby on Rails and what are its core design philosophies?
Explain the MVC architecture in Rails.
What does the standard Rails application directory structure look like?
What is a Gem in the Ruby/Rails ecosystem?
What does `resources` do in the Rails Router? What routes does it generate?
What is the difference between `render` and `redirect_to` in a Rails Controller?
What is `before_action` in Rails and what is it used for?
What are nested resources in Rails? When should you use them?
What are Strong Parameters in Rails and why are they needed?
What is Active Record? How does Rails map model names to DB tables?
What are the types of associations in Active Record?
What is the N+1 query problem and how does Rails solve it?
What are Active Record validations? What are the most common ones?
What are Active Record Callbacks? List the important ones.
What are scopes in Active Record? When to use a scope vs. a class method?
What are the differences between `find`, `find_by`, and `where`?
What are Rails migrations? Why use them instead of raw SQL?
What is `db/schema.rb`? How does it differ from migration files?
When should you use `change` vs. separate `up`/`down` in a migration?
What is a database index and how does Rails add indexes in a migration?
How do you write a zero-downtime migration on a large production DB?
What are partials in Rails Views? How do you render a partial?
What are flash messages in Rails? What is the difference between `flash` and `flash.now`?
How does CSRF protection work in Rails?
What are Concerns in Rails and how are they used in Controllers and Models?
What is the difference between Session and Cookie in Rails?
What is a Service Object in Rails and why should you use one?
What testing types does Rails support? Distinguish unit, integration, and system tests.
What is Active Job? Why is background job processing needed in Rails?
What is Sidekiq and how does it differ from Active Job?
How do you test Active Job / Sidekiq with RSpec?
What is Action Mailer in Rails? How do you send emails asynchronously?
What is idempotency in background jobs and why does it matter?
What is the Asset Pipeline in Rails and what is its role?
What is Rack? How does Rails relate to Rack?
What are helper methods in Rails Views? Distinguish `link_to` and `form_with`.
What is the difference between `namespace` and `scope` in Rails Router?
What is a Polymorphic Association in Rails? Give a real-world example.
What is Single Table Inheritance (STI) in Active Record? When to use it, when not to?
What are transactions in Active Record? When do you need one?
What is Optimistic vs Pessimistic Locking in Rails?
What is Counter Cache in Rails and how do you use it?
Why should you not reference a model class in a migration? How do you properly handle data migrations?
What is a Layout in Rails? How do you select a different layout per controller?
What is Rails caching — what are fragment cache and Russian-doll cache?
Content negotiation in Rails — how do you use `respond_to`?
What is Rails API mode? How does it differ from a full Rails app?
What is Factory Bot? How does it differ from fixtures?
What are mocks and stubs in RSpec? When to use each?
What is DatabaseCleaner in Rails testing? What are the common strategies?
Cron jobs in Rails — `whenever` gem vs Active Job scheduler? How do you set up a scheduled job?
How do retry and the dead queue work in Sidekiq?
What is an Enum in Active Record? How do you define and use it in queries?
How do `delete` and `destroy` differ in Active Record?
How do `after_save` and `after_commit` differ in transaction timing?
When should you use `has_many :through` instead of `has_and_belongs_to_many`?
How does Active Storage attach files to a model?
What is scaffolding in Rails?
How do `save`, `save!`, `update`, and `update_attribute` differ?
How do `pluck`, `select`, and `map` differ when you only need one column?
What does it mean that `ActiveRecord::Relation` is lazy? When does the query actually hit the DB?
To process 5 million records, do you use `each` or `find_each`? Why?
How do `includes`, `preload`, and `eager_load` differ? When do you use each?
When should you **not** use Active Record callbacks? What do you use instead?
How do you use low-level caching with `Rails.cache.fetch`? What matters about keys and expiry?
What should you watch out for when passing arguments to `perform_later`? Can you pass an Active Record object?
How do you write a Rack middleware that logs request duration? Where do you insert it in the stack?
On an association, how do `size`, `count`, and `length` differ?
The `Order` model has grown to 900 lines. How do you refactor — concern, service object, or a plain Ruby object?
A user double-clicks "Place order" and only 1 item is left in stock. How do you design the flow so you neither oversell nor create duplicate orders?
You need to add an index to a 50-million-row Postgres table in production. How do you write the migration so it does not block writes?