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:
What is Ruby on Rails?
- Explain the MVC (Model-View-Controller) architecture in Rails.
- Discuss the advantages of using Rails for web development.
What are RESTful routes in Rails?
- Explain the seven RESTful routes and their corresponding HTTP methods.
What is ActiveRecord?
- Describe how ActiveRecord simplifies database interactions in Rails.
- Discuss the conventions used by ActiveRecord for naming models and associations.
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.
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.
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.
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.
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.
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), andcssbundling-rails/tailwindcss-rails.
What are routes.rb and application.rb files in Rails?
- Explain the purpose of the
config/routes.rbandconfig/application.rbfiles in a Rails application. - Discuss common configurations and customizations done in these files, and the routing conventions and best practices used in Rails applications.
- Explain the purpose of the
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.
What is the difference between
redirect_toandrenderin Rails?- Explain when to use
redirect_toandrenderin controller actions. - Discuss the impact of each method on the HTTP response, the response cycle and the user’s browsing experience.
- Explain when to use
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
transactionblocks.
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.
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.
What is the difference between
has_many,has_one,belongs_to, andhas_and_belongs_to_manyassociations 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.
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.
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.
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.
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.
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.
What is the purpose of the
rails generatecommand?- Explain how the
rails generatecommand 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.
- Explain how the
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.
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.
What is the purpose of the
rails db:migratecommand?- Explain how the
rails db:migratecommand is used to apply database migrations and modify the database schema. - Discuss common options and flags available for the
db:migratecommand in Rails.
- Explain how the
What is the purpose of the
has_secure_passwordmethod in Rails models?- Explain how
has_secure_passwordis used to securely manage passwords in Rails models. - Discuss the features provided by
has_secure_password, such as password hashing and authentication methods.
- Explain how
What is the
rails routescommand used for?- Explain how the
rails routescommand is used to display the list of defined routes in a Rails application. - Discuss common options and flags available for the
rails routescommand and their use cases, such as debugging routing issues.
- Explain how the
What is the purpose of the
before_actionandafter_actioncallbacks in Rails controllers?- Explain how
before_actionandafter_actioncallbacks 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.
- Explain how
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.
What is the role of the
rails db:seedcommand?- Explain how the
rails db:seedcommand is used to populate the database with initial data. - Discuss best practices for using the
db:seedcommand and managing seed data in Rails applications.
- Explain how the
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 theactionpack-page_cachingandactionpack-action_cachinggems in Rails 4.0.
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.
What is the purpose of the
rails db:rollbackcommand? When would you use it?- Explain how the
rails db:rollbackcommand is used to revert the last database migration. - Discuss common scenarios where the
db:rollbackcommand would be used, such as rolling back a migration that caused issues during development.
- Explain how the
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.
What is the purpose of the
rails db:schema:loadcommand?- Explain how the
rails db:schema:loadcommand is used to recreate the database schema from the schema.rb file. - Discuss differences between
db:schema:loadanddb:migratecommands and their use cases.
- Explain how the
What is the purpose of the
rails db:setupcommand? When would you use it?- Explain how the
rails db:setupcommand is used to create the database, load the schema, and seed the database in one step. - Discuss common scenarios where the
db:setupcommand would be used, such as setting up a new development environment.
- Explain how the
What is the purpose of the
rails db:createcommand?- Explain how the
rails db:createcommand is used to create a new database for the Rails application. - Discuss scenarios where the
db:createcommand would be used, such as setting up a new development environment.
- Explain how the
What is the purpose of the
rails generate migrationcommand?- Explain how the
rails generate migrationcommand 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.
- Explain how the
What is the purpose of the
form_withhelper in Rails views?- Explain how
form_withis 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 olderform_forandform_taghelpers, and why it is the one to use in new code.
- Explain how
What is the difference between
rakeandrailscommands in Rails?- Explain the differences between
rakeandrailscommands and their respective roles in a Rails application. - Discuss examples of tasks that are commonly executed using
rakeandrailscommands.
- Explain the differences between
What is the purpose of the
has_many :throughassociation in Rails?- Explain how the
has_many :throughassociation is used to set up many-to-many relationships between ActiveRecord models in Rails. - Discuss examples of scenarios where
has_many :throughassociations would be used.
- Explain how the
What is the purpose of the
before_validationcallback in Rails models?- Explain how the
before_validationcallback is used to execute logic before model validation occurs in Rails. - Discuss common use cases for
before_validationcallbacks, such as normalizing data or setting default values, and compare it withnormalizes(Rails 7.1+).
- Explain how the
What is the purpose of the
touch: trueoption in Rails associations?- Explain how the
touch: trueoption is used to update the parent record’supdated_attimestamp when an associated record is saved or destroyed. - Discuss scenarios where the
touch: trueoption would be useful, such as expiring cached fragments of the parent.
- Explain how the
What is the role of the
respond_toblock in Rails controllers?- Explain how the
respond_toblock 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_toblock, such as HTML, JSON, XML, and CSV.
- Explain how the
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.
What is the role of the
before_savecallback in Rails models?- Explain how the
before_savecallback is used to execute logic before a model is saved to the database in Rails. - Discuss common use cases for
before_savecallbacks, such as deriving or denormalizing attribute values, and why password hashing belongs inhas_secure_passwordand data checks in validations rather than in abefore_savecallback.
- Explain how the
What is the purpose of the
has_one :throughassociation in Rails?- Explain how the
has_one :throughassociation 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 :throughassociations would be used.
- Explain how the
What is the purpose of the
rails generate scaffoldcommand? How do you use it?- Explain how the
rails generate scaffoldcommand 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 scaffoldcommand and its pros and cons.
- Explain how the
What is the purpose of the
includesmethod in ActiveRecord queries, and how does it differ fromjoins?- Explain how the
includesmethod is used to eager load associations and avoid N+1 query problems in Rails. - Discuss the differences between
includes,preload,eager_loadandjoins, including their impact on the resulting dataset and performance.
- Explain how the
What is the difference between
has_many :throughandhas_and_belongs_to_manyassociations in Rails?- Explain the differences between
has_many :throughandhas_and_belongs_to_manyassociations in ActiveRecord and when to use each one. - Discuss examples of scenarios where each type of association would be appropriate.
- Explain the differences between
What is the purpose of the
find_bymethod in ActiveRecord queries?- Explain how the
find_bymethod is used to retrieve records from the database based on specified conditions in Rails. - Discuss alternatives to
find_byand their use cases, such aswhereandfind.
- Explain how the
What is the purpose of the
current_usermethod in Rails applications?- Explain how the
current_usermethod 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.
- Explain how the
What is the purpose of the
before_createcallback in Rails models?- Explain how the
before_createcallback is used to execute logic before a new record is created in the database in Rails. - Discuss common use cases for
before_createcallbacks, such as generating unique identifiers or setting default attribute values.
- Explain how the
What is the purpose of the
link_tohelper in Rails views?- Explain how the
link_tohelper is used to generate HTML anchor tags with appropriate URLs in Rails views. - Discuss common options and arguments accepted by the
link_tohelper and their use cases.
- Explain how the
What is the purpose of the
dependentoption in Rails associations?- Explain how the
dependentoption is used to define the behavior of associated records when the parent record is destroyed in Rails. - Discuss common values for the
dependentoption::destroy,:destroy_async(destroys them in a background job),:delete_allforhas_manyand:deleteforhas_one/belongs_to(delete directly in SQL, skipping callbacks),:nullify,:restrict_with_exception, and:restrict_with_error.
- Explain how the
What is the purpose of the
accepts_nested_attributes_formethod in Rails models?- Explain how the
accepts_nested_attributes_formethod is used to handle nested attributes for associated models in Rails. - Discuss common use cases for
accepts_nested_attributes_forand its impact on form submissions and database updates.
- Explain how the
What is the purpose of the
rails db:migrate:statuscommand?- Explain how the
rails db:migrate:statuscommand is used to display the status of migrations in a Rails application, including pending and applied migrations. - Discuss common scenarios where the
db:migrate:statuscommand would be useful, such as tracking the progress of migrations in a development or production environment.
- Explain how the
What is the purpose of the
rails credentialscommand?- Explain how the
rails credentialscommand 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.
- Explain how the
What is the purpose of the
has_secure_tokenmethod in Rails models?- Explain how the
has_secure_tokenmethod 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.
- Explain how the
What is the purpose of the
inverse_ofoption in Rails associations?- Explain how the
inverse_ofoption is used to specify the inverse relationship between associated models in Rails. - Discuss the benefits of using
inverse_ofto improve performance and prevent unnecessary database queries.
- Explain how the
What is the purpose of the
delegatemethod in Rails models?- Explain how the
delegatemethod is used to delegate method calls to associated objects in Rails models. - Discuss common use cases for
delegateand its benefits in keeping model code concise and readable.
- Explain how the
What is the purpose of the
acts_as_listgem in Rails?- Explain how the
acts_as_listgem 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.
- Explain how the
What is the purpose of the
polymorphicoption in Rails associations?- Explain how the
polymorphicoption is used to create polymorphic associations between ActiveRecord models in Rails. - Discuss examples of scenarios where
polymorphicassociations would be useful, such as comments on multiple types of content.
- Explain how the
What is the purpose of the
counter_cacheoption in Rails associations?- Explain how the
counter_cacheoption is used to cache the number of associated records in Rails models. - Discuss the benefits of using
counter_cacheto improve performance and reduce database queries.
- Explain how the
What is the purpose of the
public_activitygem in Rails?- Explain how the
public_activitygem 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.
- Explain how the
What is the purpose of the
friendly_idgem in Rails?- Explain how the
friendly_idgem 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.
- Explain how the
What is the purpose of the
cancancangem in Rails?- Explain how the
cancancangem 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.
- Explain how the
Rails 7 and Rails 8
Recent Rails versions changed the default stack, so expect questions like these as well:
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.
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
classicautoloader, and how to debug naming errors withbin/rails zeitwerk:check.
What is Active Record Encryption?
- Explain how
encrypts :attributeencrypts a column transparently, and how keys are generated withbin/rails db:encryption:initand stored in credentials. - Discuss the trade-off between non-deterministic (default) and deterministic encryption, and why only deterministic encryption can be queried.
- Explain how
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.
How does Rails support multiple databases?
- Explain how
connects_tosets up writer and replica connections, and how automatic role switching sends reads to a replica. - Discuss horizontal sharding, the
ShardSelectormiddleware, and limitations such as no built-in load balancing of replicas.
- Explain how
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.
Public comments are closed, but I love hearing from readers. Feel free to contact me with your thoughts.