Skip to content

๐ŸŸฃ Ruby on Rails interview questions and answers to help you prepare for your next technical interview in 2025.

Notifications You must be signed in to change notification settings

Devinterview-io/ruby-on-rails-interview-questions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 

Repository files navigation

Top 72 Ruby on Rails interview questions and answers in 2021.

You can check all 72 Ruby on Rails interview questions here ๐Ÿ‘‰ https://devinterview.io/dev/rubyOnRails-interview-questions


๐Ÿ”น 1. What Is ORM In Rails?

Answer:

ORM tends for Object-Relationship-Model, where Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 2. Explain what is rake in Rails?

Answer:

Rake is a Ruby Make; it is a Ruby utility that substitutes the Unix utility โ€˜makeโ€™, and uses a โ€˜Rakefileโ€™ and โ€˜.rake filesโ€™ to build up a list of tasks. In Rails, Rake is used for normal administration tasks like migrating the database through scripts, loading a schema into the database, etc.

Source:ย career.guru99.comย  ย 


๐Ÿ”น 3. Explain what is Ruby on Rails?

Answer:

  • Ruby: It is an object-oriented programming language inspired by PERL and Python
  • Rails: It is a framework used for building web applications
Source:ย Stackoverflow.comย  ย 


๐Ÿ”น 4. Mention what is Rails Migration?

Answer:

Rails Migration enables Ruby to make changes to the database schema, making it possible to use a version control system to leave things synchronized with the actual code.

Source:ย career.guru99.comย  ย 


๐Ÿ”น 5. Explain what is ORM (Object-Relationship-Model) in Rails?

Answer:

ORM or Object Relationship Model in Rails indicate that your classes are mapped to the table in the database, and objects are directly mapped to the rows in the table.

Source:ย career.guru99.comย  ย 


๐Ÿ”น 6. Explain what is the role of sub-directory app/controllers and app/helpers?

Answer:

  • App/controllers: A web request from the user is handled by the Controller. The controller sub-directory is where Rails looks to find controller classes
  • App/helpers: The helperโ€™s sub-directory holds any helper classes used to assist the view, model and controller classes.
Source:ย career.guru99.comย  ย 


๐Ÿ”น 7. Explain what is Rails Active Record in Ruby on Rails?

Answer:

Rails active record is the Object/Relational Mapping (ORM) layer supplied with Rails. It follows the standard ORM model as

  • Table map to classes
  • Rows map to objects
  • Columns map to object attributes
Source:ย career.guru99.comย  ย 


๐Ÿ”น 8. Mention what are the limits of Ruby on Rails?

Answer:

Ruby on Rails has been designed for creating a CRUD web application using MVC. Some of the features that Rails does not support include:

  • Foreign key in databases
  • Linking to multiple database at once
  • Soap web services
  • Connection to multiple database servers at once
Source:ย career.guru99.comย  ย 


๐Ÿ”น 9. Mention what is the role of Rails Controller?

Answer:

The Rails controller is the logical center of the application. It facilitates the interaction between the users, views, and the model. It also performs other activities like

  • It is capable of routing external requests to internal actions. It handles URL extremely well
  • It regulates helper modules, which extend the capabilities of the view templates without bulking of their code
  • It regulates sessions; that gives users the impression of an ongoing interaction with our applications
Source:ย career.guru99.comย  ย 


๐Ÿ”น 10. What is the use of load and require in Ruby?

Answer:

  • You use load() to execute code
  • use require() to import libraries.
Source:ย anilpunjabi.tumblr.comย  ย 


๐Ÿ”น 11. What Do You Mean By Render And Redirect_to?

Answer:

  • render causes rails to generate a response whose content is provided by rendering one of your templates. Means, it will direct goes to view page.

  • redirect_to generates a response that, instead of delivering content to the browser, just tells it to request another url. Means it first checks actions in controller and then goes to view page.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 12. What Are Helpers And How To Use Helpers In ROR?

Answer:

Helpers are modules that provide methods which are automatically usable in your view. They provide shortcuts to commonly used display code and a way for you to keep the programming out of your views. The purpose of a helper is to simplify the view.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 13. What Are The Various Components Of Rail?

Answer:

  1. Action Pack: Action Pack is a single gem that contains Action Controller, Action View and Action Dispatch. The "VC" part of "MVC".
  • Action Controller: Action Controller is the component that manages the controllers in a Rails application. The Action Controller framework processes incoming requests to a Rails application, extracts parameters, and dispatches them to the intended action.

  • Action View: Action View manages the views of your Rails application. It can create both HTML and XML output by default. Action View manages rendering templates, including nested and partial templates, and includes built-in AJAX support.

  • Action Dispatch: Action Dispatch handles routing of web requests and dispatches them as you want, either to your application or any other Rack application. Rack applications are a more advanced topic and are covered in a separate guide called Rails on Rack.

  1. Action Mailer: Action Mailer is a framework for building e-mail services. You can use Action Mailer to receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates.

  2. Active Model: Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.

  3. Active Record: Active Record are like Object Relational Mapping (ORM), where classes are mapped to table, objects are mapped to columns and object attributes are mapped to data in the table.

  4. Active Resource: Active Resource provides a framework for managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUD semantics.

  5. Active Support: Active Support is an extensive collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 14. How Is Visibility Of Methods Changed In Ruby (encapsulation)?

Answer:

By applying the access modifier:

  • Public,
  • Private and
  • Protected
Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 15. What do you mean by the term Scaffolding and what sort of advantages the Ruby can offer when it comes to same?

Answer:

While developing the projects, the users often have to write codes in the early stage of development. These codes help building the application in a very reliable manner and quickly and also, a close eye can be kept on the working of some major components with this approach. In Ruby, the scaffolding is done automatically and the users are free to concentrate on the core development only from the first day of development.

Source:ย mindmajix.comย  ย 


๐Ÿ”น 16. What Is MVC? And How It Works?

Answer:

MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like this:

Request first comes to the controller, controller finds and appropriate view and interacts with model, model interacts with your database and send the response to controller then controller based on the response give the output parameter to view.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 17. Explain how you define Instance Variable, Global Variable and Class Variable in Ruby?

Answer:

  • Ruby Instance variable begins with โ€” @
  • Ruby Class variables begin with โ€” @@
  • Ruby Global variables begin with โ€” $
Source:ย career.guru99.comย  ย 


๐Ÿ”น 18. How Many Types Of Relationships Does A Model Has?

Answer:

  1. has_one
  2. belongs_to
  3. has_many
  4. has_many :through
Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 19. Mention what are the positive aspects of Rails?

Answer:

Rails provides many features like:

  • Meta-programming: Rails uses code generation but for heavy lifting it relies on meta-programming. Ruby is considered as one of the best language for Meta-programming.
  • Active Record: It saves object to the database through Active Record Framework. The Rails version of Active Record identifies the column in a schema and automatically binds them to your domain objects using metaprogramming
  • Scaffolding: Rails have an ability to create scaffolding or temporary code automatically
  • Convention over configuration: Unlike other development framework, Rails does not require much configuration, if you follow the naming convention carefully
  • Three environments: Rails comes with three default environment testing, development, and production.
  • Built-in-testing: It supports code called harness and fixtures that make test cases to write and execute.
Source:ย career.guru99.comย  ย 


๐Ÿ”น 20. Mention what is the difference between a gem and a plugin in Ruby?

Answer:

  • Gem: A gem is a just ruby code. It is installed on a machine, and itโ€™s available for all ruby applications running on that machine.
  • Plugin: Plugin is also ruby code, but it is installed in the application folder and only available for that specific application.
Source:ย career.guru99.comย  ย 


๐Ÿ”น 21. How Many Types Of Associations Relationships Does A Model Have?

Answer:

When you have more than one model in your rails application, you would need to create connection between those models. You can do this via associations. Active Record supports three types of associations:

  • one-to-one: A one-to-one relationship exists when one item has exactly one of another item. For example, a person has exactly one birthday or a dog has exactly one owner.

  • one-to-many: A one-to-many relationship exists when a single object can be a member of many other objects. For instance, one subject can have many books.

  • many-to-many: A many-to-many relationship exists when the first object is related to one or more of a second object, and the second object is related to one or many of the first object.

You indicate these associations by adding declarations to your models:

  • has_one,
  • has_many,
  • belongs_to,
  • has_and_belongs_to_many
Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 22. Explain what is a class library in Ruby?

Answer:

Ruby class libraries consist of a variety of domains, such as thread programming, data types, various domains, etc. These classes give flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains. The following domains which have relevant class libraries are,

  • GUI programming
  • Network programming
  • CGI Programming
  • Text processing
Source:ย career.guru99.comย  ย 


๐Ÿ”น 23. List out what can Rails Migration do?

Answer:

Rails Migration can do following things

  • Create table
  • Drop table
  • Rename table
  • Add column
  • Rename column
  • Change column
  • Remove column and so on
Source:ย career.guru99.comย  ย 


๐Ÿ”น 24. What Is The Difference Between Nil And False In Ruby?

Answer:

False is a boolean datatype, Nil is not a data type it have object_id 4.

Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 25. What is the purpose of the resources method in the code snippet below?

Answer:

Problem

Consider:

resources :posts do
  member do
      get โ€˜messagesโ€™
  end
  collection do
      post โ€˜bulk_upload'
  end
end

Defining routes with the resources method automatically generates routes for the seven standard RESTful actions:

  • GET /messages
  • POST /messages
  • GET /messages/new
  • GET /messages/:id/edit
  • GET /messages/:id
  • PATCH/PUT /messages/:id
  • DELETE /messages/:id
Source:ย upwork.comย  ย 


๐Ÿ”น 26. Mention what is the difference in scope for these two variables: @@name and @name?

Answer:

The difference in scope for these two variables is that:

  • @@name is a class variable
  • @name is an instance variable
Source:ย career.guru99.comย  ย 


๐Ÿ”น 27. What Things We Can Define In The Model?

Answer:

There are lot of things you can define in models, the few are:

  1. Validations (like validates_presence_of, numeracility_of, format_of etc.)
  2. Relationships (like has_one, has_many, HABTM etc.)
  3. Callbacks (like before_save, after_save, before_create etc.)
  4. Suppose you installed a plugin say validation_group, So you can also define validation_group settings in your model
  5. ROR Queries in Sql
  6. Active record Associations Relationship
Source:ย wisdomjobs.com/ย  ย 


๐Ÿ”น 28. How should you use nested layouts?

Answer:

The layouts removes code duplication in view layer. You are able to slice all your application pages to blocks such as header, footer, sidebar, body and etc.

A generated Rails application has a default layout and itโ€™s defined in the app/views/layouts/application.html.erb. On the screen above there is only one dynamic block - itโ€™s the body, the footer, the header and the sidebar are common blocks for each page. So the code for the layout may look like this:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
  <%= render 'shared/header' %>
  <%= render 'shared/sidebar' %>
  <%= yield %>
  <%= render 'shared/footer' %>
</html>

The yield in the code above is the place in which any action template will be rendered. This is a default Rails behavior.

Source:ย railsguides.netย  ย 


๐Ÿ”น 29. What is the purpose of the rakefile available in the demo directory in Ruby?

Answer:

The purpose of this simple question is to make sure a developer is familiar with a test-driven development. A beginner may not have dealt with this file yet. The rakefile is similar to the makefile in Unix, and assists with packaging and testing Rails code. Itโ€™s used by the rake utility, which ships natively with the Ruby installation.

Source:ย upwork.comย  ย 


๐Ÿ”น 30. Mention what is the function of garbage collection in Ruby on Rails?

Answer:

The functions of garbage collection in Ruby on Rails includes

  • It enables the removal of the pointer values which is left behind when the execution of the program ends
  • It frees the programmer from tracking the object that is being created dynamically on runtime
  • It gives the advantage of removing the inaccessible objects from the memory, and allows other processes to use the memory
Source:ย career.guru99.comย  ย 


๐Ÿ”น 31. How does Ruby on Rails use the Model View Controller (MVC) framework?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 32. What is the use of Destructive Method?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 33. Mention what is the purpose of RJs in Rails?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 34. What Are Filters?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 35. Mention what is the difference between the Observers and Callbacks in Ruby on Rails?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 36. Explain what is Polymorphic Association in Ruby on Rails?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 37. Explain what is Interpolation in Ruby?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 38. What exactly are Harnesses and Fixtures in the Ruby?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 39. What is the difference between &&, || operators and "and, or"?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 40. Can you explain the difference between ActiveSupportโ€™s โ€œHashWithIndifferentAccessโ€ and Rubyโ€™s โ€œHashโ€?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 41. What is the difference between symbol and string?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 42. What Is The Difference Between Delete And Destroy?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 43. What Is A Proc?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 44. Mention what is the difference between calling super() and super call?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 45. Practical test: Genres of music

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 46. Explain Ruby on Rails Exception Handling

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 47. What is the difference between string and text in Rails?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 48. What is the Difference Between Gem And Plugin?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 49. What is ActiveJob? When should we use it?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 50. What Is The Difference Between "Save" And "Save!"?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 51. Is Rails Scalable?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 52. What are Strong Parameters?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 53. What Do You Mean By Naming Convention In Rails?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 54. Does Ruby Support Single Inheritance/multiple Inheritance Or Both?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 55. What is Rack?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 56. What Is The Flash?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 57. How Many Types Of Callbacks Available In Ror?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 58. Explain the difference between Page, Action, Fragment, Low-Level, SQL caching types.

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 59. What is the difference between content_for and yield?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 60. How would you choose between Belongs_to And Has_one?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 61. What Are Filters? And How Many Types Of Filters Are There In Ruby?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 62. What is Dynamic Finders?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 63. What sort of problems you have faced with Ruby on Rails and how do you think the same can affect the projects?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 64. What is the best thing which you find about the Ruby on Rail so far?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 65. How To Use Two Databases Into A Single Application?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 66. What is a Rails engine?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 67. Node.js vs Ruby on Rails. Which would you choose?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 68. What is Asset Pipeline?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 69. How To Find Second Max Element From Database?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 70. How to check if a specific key is present in a hash or not?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 71. How to rollback a specific migration?

๐Ÿ‘‰๐Ÿผ Check all 72 answers


๐Ÿ”น 72. How Do I Find Only Duplicate Entries In A Database Table?

๐Ÿ‘‰๐Ÿผ Check all 72 answers



Thanks ๐Ÿ™Œ for reading and good luck on your next tech interview!
Explore 3800+ dev interview question here ๐Ÿ‘‰ Devinterview.io