Updated October 2026: Removed duplicate questions, modernised the asset pipeline, forms, caching, serializer and callback questions for Rails 7/8, and added a Rails 7 and Rails 8 section.

Preparing for a Ruby on Rails web development interview requires a solid understanding of web development concepts, Ruby programming language, and the Rails framework. Here’s a list of common interview questions that cover various aspects of web development and Ruby on Rails:

  1. What is Ruby on Rails?

    • Explain the MVC (Model-View-Controller) architecture in Rails.
    • Discuss the advantages of using Rails for web development.
  2. What are RESTful routes in Rails?

    • Explain the seven RESTful routes and their corresponding HTTP methods.
  3. What is ActiveRecord?

    • Describe how ActiveRecord simplifies database interactions in Rails.
    • Discuss the conventions used by ActiveRecord for naming models and associations.
  4. What are migrations in Rails?

    • Explain the purpose of migrations and how they are used to modify the database schema.
    • Discuss best practices for writing migrations in Rails.
  5. What is the role of a controller in Rails?

    • Explain how controllers handle incoming requests and generate responses.
    • Discuss the use of filters and callbacks in controllers.
  6. What is a view in Rails?

    • Describe how views are used to generate HTML responses in Rails.
    • Discuss the use of layouts, partials, and helpers in views.
  7. What is CSRF protection in Rails?

    • Explain what CSRF (Cross-Site Request Forgery) is and how Rails protects against it.
    • Discuss how CSRF tokens are generated and validated in Rails applications.
    • Discuss how Rails form helpers include the token automatically and why every form that changes state needs it.
  8. What are helpers in Rails?

    • Explain the role of helpers in Rails and how they are used to encapsulate view logic.
    • Discuss different types of helpers and their usage.
  9. What is the asset pipeline in Rails, and how has it changed?

    • Describe the purpose of the asset pipeline: organizing, fingerprinting and serving CSS, JavaScript and images.
    • Compare Sprockets (the legacy pipeline, with concatenation and compression) with Propshaft, the default since Rails 8, which only fingerprints and serves assets and leaves transpiling and bundling to other tools.
    • Discuss the JavaScript and CSS options that pair with it: importmap-rails (no build step), jsbundling-rails (esbuild, Bun, rollup.js, Webpack), and cssbundling-rails / tailwindcss-rails.
  10. What are routes.rb and application.rb files in Rails?

    • Explain the purpose of the config/routes.rb and config/application.rb files in a Rails application.
    • Discuss common configurations and customizations done in these files, and the routing conventions and best practices used in Rails applications.
  11. What is TDD (Test-Driven Development) in Rails?

    • Explain the principles of TDD and its benefits in Rails development.
    • Discuss popular testing frameworks and tools used in Rails, such as RSpec and Capybara.
  12. What is the difference between redirect_to and render in Rails?

    • Explain when to use redirect_to and render in controller actions.
    • Discuss the impact of each method on the HTTP response, the response cycle and the user’s browsing experience.
  13. How does Rails handle database transactions?

    • Explain the role of database transactions in ensuring data consistency in Rails applications.
    • Discuss methods for managing transactions in Rails, such as transaction blocks.
  14. What are gems in Rails, and how do you manage them?

    • Explain what gems are and how they are used to extend the functionality of Rails applications.
    • Discuss the process of managing gems with Bundler (Gemfile, Gemfile.lock, installing, updating and removing gems), and common gems used in Rails development and their purposes.
  15. What is the role of middleware in Rails?

    • Explain how middleware works in Rails and its role in processing HTTP requests and responses.
    • Discuss examples of middleware used in Rails applications.
  16. What is the difference between has_many, has_one, belongs_to, and has_and_belongs_to_many associations in Rails?

    • Explain the different types of associations in ActiveRecord and when to use each one.
    • Discuss examples of scenarios where each type of association would be appropriate.
  17. What is the purpose of callbacks in Rails?

    • Explain how callbacks are used to trigger logic at certain points in the lifecycle of ActiveRecord objects.
    • Discuss the different types of callbacks available in Rails and their order of execution.
  18. What are concerns in Rails?

    • Explain how concerns are used to modularize and organize shared behavior in Rails models.
    • Discuss the advantages and best practices for using concerns in Rails applications.
  19. What is the purpose of asset fingerprinting in Rails?

    • Explain how asset fingerprinting works and its role in cache-busting and asset versioning.
    • Discuss how asset fingerprinting improves cache efficiency and reduces browser requests for assets.
  20. What is the purpose of the rails console? How do you use it?

    • Explain how to use the Rails console to interact with the Rails application and its database.
    • Discuss common use cases for the Rails console in debugging, testing, and exploring application data.
  21. What are strong parameters in Rails?

    • Explain the purpose of strong parameters and how they are used to prevent mass assignment vulnerabilities in Rails controllers.
    • Discuss best practices for using strong parameters and permitting parameters in Rails applications.
  22. What is the purpose of the rails generate command?

    • Explain how the rails generate command is used to generate various components of a Rails application, such as models, controllers, views, and migrations.
    • Discuss common generators and their options available in Rails.
  23. What are the different environments in a Rails application?

    • Explain the concept of environments in Rails, such as development, test, and production.
    • Discuss how environment-specific configuration settings are managed in Rails applications.
  24. What is ActiveRecord::Relation in Rails?

    • Explain the concept of ActiveRecord::Relation and its role in constructing database queries in Rails.
    • Discuss methods available on ActiveRecord::Relation objects for querying and manipulating data.
  25. What is the purpose of the rails db:migrate command?

    • Explain how the rails db:migrate command is used to apply database migrations and modify the database schema.
    • Discuss common options and flags available for the db:migrate command in Rails.
  26. What is the purpose of the has_secure_password method in Rails models?

    • Explain how has_secure_password is used to securely manage passwords in Rails models.
    • Discuss the features provided by has_secure_password, such as password hashing and authentication methods.
  27. What is the rails routes command used for?

    • Explain how the rails routes command is used to display the list of defined routes in a Rails application.
    • Discuss common options and flags available for the rails routes command and their use cases, such as debugging routing issues.
  28. What is the purpose of the before_action and after_action callbacks in Rails controllers?

    • Explain how before_action and after_action callbacks are used to execute code before and after controller actions, respectively.
    • Discuss examples of scenarios where they would be useful, such as authentication, authorization, and setting up instance variables.
  29. What is Active Job in Rails?

    • Explain the purpose of Active Job and its role in handling background jobs in Rails applications.
    • Discuss how Active Job simplifies the implementation of asynchronous and background processing tasks.
  30. What is the role of the rails db:seed command?

    • Explain how the rails db:seed command is used to populate the database with initial data.
    • Discuss best practices for using the db:seed command and managing seed data in Rails applications.
  31. What is the purpose of caching in Rails?

    • Explain how caching is used to improve the performance and scalability of Rails applications by storing and reusing frequently accessed data.
    • Discuss the caching strategies built into Rails, such as fragment (Russian doll) caching, low-level caching with Rails.cache, and conditional GET (ETags), and note that page and action caching were extracted from core into the actionpack-page_caching and actionpack-action_caching gems in Rails 4.0.
  32. What is the difference between partials and layouts in Rails views?

    • Explain the differences between partials and layouts in Rails views and when to use each one.
    • Discuss how partials and layouts help in organizing and reusing view code in Rails applications.
  33. What is the purpose of the rails db:rollback command? When would you use it?

    • Explain how the rails db:rollback command is used to revert the last database migration.
    • Discuss common scenarios where the db:rollback command would be used, such as rolling back a migration that caused issues during development.
  34. What are serializers in Rails?

    • Explain the purpose of serializers and how they are used to format and serialize data for APIs and other external systems.
    • Discuss popular serialization options used in Rails, such as Jbuilder, Alba, and Blueprinter, and why Active Model Serializers (whose 0.10.x line is now in maintenance mode) is less common in new projects.
  35. What is the purpose of the rails db:schema:load command?

    • Explain how the rails db:schema:load command is used to recreate the database schema from the schema.rb file.
    • Discuss differences between db:schema:load and db:migrate commands and their use cases.
  36. What is the purpose of the rails db:setup command? When would you use it?

    • Explain how the rails db:setup command is used to create the database, load the schema, and seed the database in one step.
    • Discuss common scenarios where the db:setup command would be used, such as setting up a new development environment.
  37. What is the purpose of the rails db:create command?

    • Explain how the rails db:create command is used to create a new database for the Rails application.
    • Discuss scenarios where the db:create command would be used, such as setting up a new development environment.
  38. What is the purpose of the rails generate migration command?

    • Explain how the rails generate migration command is used to create new database migrations in a Rails application.
    • Discuss common use cases for creating migrations, such as adding or modifying database tables and columns.
  39. What is the purpose of the form_with helper in Rails views?

    • Explain how form_with is used to generate HTML forms in Rails views, both for a model (model:) and for a plain URL (url:).
    • Discuss how form_with (Rails 5.1+) unified the older form_for and form_tag helpers, and why it is the one to use in new code.
  40. What is the difference between rake and rails commands in Rails?

    • Explain the differences between rake and rails commands and their respective roles in a Rails application.
    • Discuss examples of tasks that are commonly executed using rake and rails commands.
  41. What is the purpose of the has_many :through association in Rails?

    • Explain how the has_many :through association is used to set up many-to-many relationships between ActiveRecord models in Rails.
    • Discuss examples of scenarios where has_many :through associations would be used.
  42. What is the purpose of the before_validation callback in Rails models?

    • Explain how the before_validation callback is used to execute logic before model validation occurs in Rails.
    • Discuss common use cases for before_validation callbacks, such as normalizing data or setting default values, and compare it with normalizes (Rails 7.1+).
  43. What is the purpose of the touch: true option in Rails associations?

    • Explain how the touch: true option is used to update the parent record’s updated_at timestamp when an associated record is saved or destroyed.
    • Discuss scenarios where the touch: true option would be useful, such as expiring cached fragments of the parent.
  44. What is the role of the respond_to block in Rails controllers?

    • Explain how the respond_to block is used to handle different types of HTTP requests and respond with appropriate formats in Rails controllers.
    • Discuss examples of formats supported by the respond_to block, such as HTML, JSON, XML, and CSV.
  45. What is the difference between SQL injection and Cross-Site Scripting (XSS) vulnerabilities?

    • Explain the differences between SQL injection and XSS vulnerabilities, including how they occur and their potential impact on web applications.
    • Discuss strategies for mitigating SQL injection and XSS vulnerabilities in Rails applications.
  46. What is the role of the before_save callback in Rails models?

    • Explain how the before_save callback is used to execute logic before a model is saved to the database in Rails.
    • Discuss common use cases for before_save callbacks, such as deriving or denormalizing attribute values, and why password hashing belongs in has_secure_password and data checks in validations rather than in a before_save callback.
  47. What is the purpose of the has_one :through association in Rails?

    • Explain how the has_one :through association is used to set up one-to-one relationships between ActiveRecord models through a third intermediate model in Rails.
    • Discuss examples of scenarios where has_one :through associations would be used.
  48. What is the purpose of the rails generate scaffold command? How do you use it?

    • Explain how the rails generate scaffold command is used to generate a complete set of resources for a model, including a controller, views, and migration files.
    • Discuss common use cases for the generate scaffold command and its pros and cons.
  49. What is the purpose of the includes method in ActiveRecord queries, and how does it differ from joins?

    • Explain how the includes method is used to eager load associations and avoid N+1 query problems in Rails.
    • Discuss the differences between includes, preload, eager_load and joins, including their impact on the resulting dataset and performance.
  50. What is the difference between has_many :through and has_and_belongs_to_many associations in Rails?

    • Explain the differences between has_many :through and has_and_belongs_to_many associations in ActiveRecord and when to use each one.
    • Discuss examples of scenarios where each type of association would be appropriate.
  51. What is the purpose of the find_by method in ActiveRecord queries?

    • Explain how the find_by method is used to retrieve records from the database based on specified conditions in Rails.
    • Discuss alternatives to find_by and their use cases, such as where and find.
  52. What is the purpose of the current_user method in Rails applications?

    • Explain how the current_user method is used to retrieve the currently authenticated user in Rails controllers and views.
    • Discuss common strategies for implementing user authentication and managing the current user session in Rails applications, such as Devise or the authentication generator added in Rails 8.
  53. What is the purpose of the before_create callback in Rails models?

    • Explain how the before_create callback is used to execute logic before a new record is created in the database in Rails.
    • Discuss common use cases for before_create callbacks, such as generating unique identifiers or setting default attribute values.
  54. What is the purpose of the link_to helper in Rails views?

    • Explain how the link_to helper is used to generate HTML anchor tags with appropriate URLs in Rails views.
    • Discuss common options and arguments accepted by the link_to helper and their use cases.
  55. What is the purpose of the dependent option in Rails associations?

    • Explain how the dependent option is used to define the behavior of associated records when the parent record is destroyed in Rails.
    • Discuss common values for the dependent option: :destroy, :destroy_async (destroys them in a background job), :delete_all for has_many and :delete for has_one/belongs_to (delete directly in SQL, skipping callbacks), :nullify, :restrict_with_exception, and :restrict_with_error.
  56. What is the purpose of the accepts_nested_attributes_for method in Rails models?

    • Explain how the accepts_nested_attributes_for method is used to handle nested attributes for associated models in Rails.
    • Discuss common use cases for accepts_nested_attributes_for and its impact on form submissions and database updates.
  57. What is the purpose of the rails db:migrate:status command?

    • Explain how the rails db:migrate:status command is used to display the status of migrations in a Rails application, including pending and applied migrations.
    • Discuss common scenarios where the db:migrate:status command would be useful, such as tracking the progress of migrations in a development or production environment.
  58. What is the purpose of the rails credentials command?

    • Explain how the rails credentials command is used to manage encrypted credentials in a Rails application, such as database passwords and API keys.
    • Discuss common use cases for storing sensitive information in encrypted credentials and best practices for managing credentials securely.
  59. What is the purpose of the has_secure_token method in Rails models?

    • Explain how the has_secure_token method is used to generate unique, random tokens for model instances in Rails.
    • Discuss common use cases for has_secure_token, such as generating authentication tokens or unique identifiers.
  60. What is the purpose of the inverse_of option in Rails associations?

    • Explain how the inverse_of option is used to specify the inverse relationship between associated models in Rails.
    • Discuss the benefits of using inverse_of to improve performance and prevent unnecessary database queries.
  61. What is the purpose of the delegate method in Rails models?

    • Explain how the delegate method is used to delegate method calls to associated objects in Rails models.
    • Discuss common use cases for delegate and its benefits in keeping model code concise and readable.
  62. What is the purpose of the acts_as_list gem in Rails?

    • Explain how the acts_as_list gem is used to add sorting functionality to ActiveRecord models in Rails.
    • Discuss common use cases for acts_as_list, such as managing the order of items in a list or menu.
  63. What is the purpose of the polymorphic option in Rails associations?

    • Explain how the polymorphic option is used to create polymorphic associations between ActiveRecord models in Rails.
    • Discuss examples of scenarios where polymorphic associations would be useful, such as comments on multiple types of content.
  64. What is the purpose of the counter_cache option in Rails associations?

    • Explain how the counter_cache option is used to cache the number of associated records in Rails models.
    • Discuss the benefits of using counter_cache to improve performance and reduce database queries.
  65. What is the purpose of the public_activity gem in Rails?

    • Explain how the public_activity gem is used to track and record activities and events in a Rails application.
    • Discuss common use cases for public_activity, such as auditing changes to records or generating activity feeds.
  66. What is the purpose of the friendly_id gem in Rails?

    • Explain how the friendly_id gem is used to generate human-readable, SEO-friendly slugs for ActiveRecord models in Rails.
    • Discuss common use cases for friendly_id, such as improving the readability and search engine optimization of URLs.
  67. What is the purpose of the cancancan gem in Rails?

    • Explain how the cancancan gem is used to implement role-based authorization and access control in a Rails application.
    • Discuss common use cases for cancancan, such as restricting access to certain resources based on user roles and permissions.

Rails 7 and Rails 8

Recent Rails versions changed the default stack, so expect questions like these as well:

  1. What is Hotwire, and how do Turbo and Stimulus fit together?

    • Explain how Turbo Drive, Turbo Frames and Turbo Streams update pages by sending HTML over the wire instead of JSON.
    • Discuss when Stimulus controllers are needed and when you would still reach for a JavaScript framework.
  2. What is Zeitwerk, and how does autoloading work in Rails?

    • Explain the file name to constant name conventions Zeitwerk relies on, and the difference between autoloading in development and eager loading in production.
    • Discuss what changed when Rails 7 removed the classic autoloader, and how to debug naming errors with bin/rails zeitwerk:check.
  3. What is Active Record Encryption?

    • Explain how encrypts :attribute encrypts a column transparently, and how keys are generated with bin/rails db:encryption:init and stored in credentials.
    • Discuss the trade-off between non-deterministic (default) and deterministic encryption, and why only deterministic encryption can be queried.
  4. What are Solid Queue, Solid Cache and Solid Cable?

    • Explain how these database-backed adapters, part of the Rails 8 stack, replace Redis (and job runners such as Sidekiq or Resque) for background jobs, caching, and Action Cable pub/sub.
    • Discuss when a dedicated Redis or Memcached setup is still worth it.
  5. How does Rails support multiple databases?

    • Explain how connects_to sets up writer and replica connections, and how automatic role switching sends reads to a replica.
    • Discuss horizontal sharding, the ShardSelector middleware, and limitations such as no built-in load balancing of replicas.
  6. What is Kamal, and how do you deploy a Rails 8 application?

    • Explain how Kamal 2 (preconfigured in new Rails 8 apps) deploys Docker containers to your own servers, and the role of Thruster in front of Puma.
    • Discuss how this compares with deploying to a PaaS such as Heroku.