Ruby on Rails Interview Questions and Answers

Rails interviews test convention-over-configuration thinking: how a request flows through routes, controllers, models and views, how ActiveRecord maps tables and associations, validations, scopes and migrations, and when callbacks help or hurt.

Performance and production topics follow: the N+1 query problem and eager loading, database indexes, caching layers, background jobs, security defaults (strong parameters, CSRF, SQL injection) and test strategy. Senior rounds ask how you would structure a large Rails app and keep models thin.

Questions

Related

Frequently asked questions

What is the N+1 query problem?

Loading a list of records and then querying once per record for an association. Fix it with eager loading (includes, preload or eager_load) so the associations load in one or two queries.

Are callbacks bad practice?

Not by themselves, but business logic hidden in callbacks is hard to test and reason about. Prefer explicit service objects for multi-step workflows and keep callbacks for simple, local concerns.

How do you keep Rails controllers thin?

Move business logic into models or service objects, use strong parameters and concerns for shared behaviour, and keep the controller to authentication, parameters and the response.