Javatpoint Logo
Javatpoint Logo
Ruby on Rails Interview Questions

Ruby on Rails Interview Questions

A list of top frequently asked Ruby on Rails interview questions and answers are given below.

1) What is Ruby on Rails?

Ruby on Rails is a server-side web application development framework written in Ruby language. It allows you to write less code than other languages and frameworks. It includes everything needed to create database-backed web applications according to MVC pattern.

For more information: Click here

2) Explain DRY in Rails?

DRY stands for Don't Repeat Yourself. It is a principle of software development which states that "Every piece of knowledge must have an authoritative, unambiguous, single representation within a system. If the same part of the code will not repeat again and again, the code will be more maintainable, extensible and less buggy.

For more information: Click here

3) What is the current version of Ruby on rails?

Rails 5.0.1 was released on December 21, 2016. It introduced Action cable, Turbolinks 5 and API mode.

4) Explain CoC in Rails

DRY stands for Convention over Configuration. It provides different opinions on the best way to do many things in a web application.

For more information: Click here

5) Who developed Rails?

Ruby on Rails was created by David Heinemeier Hansson (DHH).

For more information: Click here

6) What are the three methods to install Ruby on Rails?

There are three methods to install Ruby on Rails:

  • Using rbenv (recommended)
  • Using rvm
  • From source

For more information: Click here

7) Name some Rails IDE or editor.

Ruby on Rails can be used with either a simple text editor or with an IDE.

Some of the Rails IDEs are listed below:

  • TextMate
  • E
  • Intellij IDEA
  • NetBeans
  • Eclipse
  • Heroku
  • Aptana Studio
  • RubyMine
  • Kuso IDE
  • Komodo
  • Redcar
  • Arcadia
  • Ice Coder

For more information: Click here

8) What is Rails script? Name some of them?

Rails provide some excellent tools that are used to develop a Rails application. These tools are packaged as scripts from command line.

Following are the most useful Rails scripts used in Rails application:

  • Rails Console
  • WEBrick Web Server
  • Generators
  • Migrations

For more information: Click here

9) Are there any disadvantages of Ruby on Rails? If yes, mention them.

Some of the features that are not supported by Ruby on rails are:

  • Linking to multiple databases.
  • Inclusion of foreign keys in database.
  • Establishing connection to various databases at a time.
  • Web services related to Soap.

10) What is the use of the super function in Ruby on Rails?

The super function in Ruby is used to invoke the original method. It calls the superclass implementation of the current method.

11) What is Active Record in Rails?

A perfect ORM hides the details of a database's relational data behind the object hierarchy. In Rails, ORM is implemented by Active Record which is one of the most critical components of the Rails library.

While using Active Record, you have to no longer deal with database constructs like tables, rows or columns. Your application only deals with classes, attributes, and objects.

For more information: Click here

12) Who designed Active Record in Rails?

Active Record is based on a design pattern created by Martin Fowler. From this design pattern only, the Active Record got its name. Its code works very well even with less number of lines. It is quite easy to use. Active Record Rails application does not need any configuration at all if proper naming schemes are followed in your database and classes.

For more information: Click here

13) Explain model in Rails?

The models are classes in Rails. This subsystem is implemented in ActiveRecord library. This library provides an interface between database tables and Ruby program code that manipulates database records.

For more information: Click here

14) Which command is used to create a migration?

18) What are the hashes?

A hash is a collection of key-value pairs.

19) How are blocks created?

The syntax for creation of block is:

20) What is the naming convention for variables?

The name of the variable is given in the lower case, and an underscore separates the different words within the name.

21) What is the main difference between procs and blocks?

Procs are objects whereas Blocks are a part of the code.

22) The string can be represented in single as well as double quotes. What is the difference between the two?

The single quote string representation is not allowed to perform string interpolation and process the ASCII escape codes.

23) Explain rails migration.

With the help of rails migration, Ruby can make changes to the database schema.

24) How would you create a controller for the subject?

You have to use the following command to create a controller for subject:

25) Explain view in Rails?

View represent data in a particular format in an application for the users. This subsystem is implemented in ActionView library. This library is an Embedded Ruby (Erb) based system which define presentation templates for data presentation.

For more information: Click here

26) Explain the controller in Rails?

The Controller directs traffic to views and models. This subsystem is implemented in ActionController library. This library is a data broker sitting between ActiveRecord and ActionView.

For more information: Click here

27) Explain RVM in Rails?

RVM stands for Ruby Version Manager. It is a command line tool which allows you to install, manage and work with different Ruby environments efficiently. With RVM, you can easily install different versions of Ruby and quickly switch between them.


The basic syntax of RVM is,

For more information: Click here

28) What are Gemsets in Rails?

Gems in Ruby are used to extend capabilities of core Ruby distribution. They add specific functionalities in programs. Some gems are also installed with Ruby installation to provide specific environments are called gemsets. You can have different versions of the same gem installed in a system.

To know all the gems available in Ruby, use the following command:

For more information: Click here

29) Write the command to update RVM in Rails.

To upgrade RVM, use the following command:

For more information: Click here

30) Explain bundler in Rails.

Rails bundler provides a constant environment for applications by tracking suitable gems that are needed.

To use bundler, use the following command:

For more information: Click here

31) Why we use migration in Rails?

Migration alters the database schema for an application in a consistent and organized manner by using DSL.

Syntax to create a migration file:

For more information: Click here

32) Write the command to run the migration.

For more information: Click here

33) How does router work in Rails?

The Rails router recognizes URLs and dispatches them to a controller's action. It also generates paths and URLs. Rails router deals with URLs differently from other language routers. It determines controller, parameters, and action for the request.

Main purpose of Rails routers is:

  • Connecting URLs to code
  • Generating paths and URLs from code

For more information: Click here

34) Explain REST in Rails routes.

REST is very beneficial to understand routes in Rails. It stands for Representational State Transfer. Several HTTP methods are used with REST to represent the types of actions performed by the user or application.

For more information: Click here

35) Explain some features of nested scaffolding.

The Nested scaffold is the command that generates a set of correctly working nested resource for Rails 4.2 and 5.


  • Generates a nested child resource with a single command
  • Generates a beautifully working bunch of code
  • Automatically generates appropriate model associations for ActiveRecord
  • Haml ready

For more information: Click here

36) In how many ways you can create Rails layout HTTP response.

There are three ways to create an HTTP response from the controller's point of view:

  • Call render to create a full response to send back to the browser
  • Call redirect_to to send an HTTP redirect status code to the browser
  • Call head to create a response to end back to the browser

For more information: Click here

37) Explain the importance of yield statement in Rails.

The yield statement in Rails decides where to render the content for the action in the layout. If there is no yield statement in the layout, the layout file itself will be rendered, but additional content into the action templates will not be correctly placed within the layout.

For more information: Click here

38) How many filters are there in Rails.

Rails filters are methods that run before or after a controller's action method is executed. Rails support three types of filter methods:

  • Before filters
  • After filters
  • Around filters

For more information: Click here

39) How can you protect filter methods in Rails?

All the Ruby methods have at least one of these protection level.

  • Public: These methods are accessible from any external class or method that uses the same class in which they are defined.
  • Protected: These methods are accessible only within the class in which they are defined and in the classes that inherit from the class in which they are defined.
  • Private: These methods are only accessible within the class in which they are defined.

For more information: Click here

40) Explain testing in Rails.

Rails also use a separate database for testing. Rails use Ruby Test::A unit testing library. Rails application test is usually run using Rake utility.

Rails support three types of tests:

  • functional
  • integration
  • unit tests

For more information: Click here

41) Explain Rails caching levels.

Rails caching is available at three levels of granularity:

  • Page
  • Action
  • Fragment

For more information: Click here

42) What are Rails validation used for?

Rails validation defines valid states for each of your Active Record model classes. They are used to ensure that only valid details are entered into your database.

For more information: Click here

43) Explain valid and invalid in Rails?

The valid? triggers your validations and returns true if no errors are found otherwise, false.

The invalid? is simply the reverse of valid?. It triggers your validations and returns true if invalid otherwise, false.

For more information: Click here

44) Explain Unobtrusive JavaScript in Rails.

"Unobtrusive JavaScript" technique is considered as the best technique within the frontend community.

For more information: Click here

45) What is the Symbol Garbage Collector?

Passing symbols opens the possibility of several attacks in your system. The symbol garbage collector collects the symbols which prevent your system from several attacks.

46) What is Action Cable?

It is a framework which is used to extend Rails via WebSockets to add some functionality. It integrates WebSockets with the rest of the Rails application very smoothly. It allows you to add some real-time features to your app quickly.

47) Explain the various IDE's of ruby on rails.

TextMate:The TextMate is mainly used for the Mac operating system. It allows you to write extensions to the base environment. The extensions plug into TextMate to add new features to the base editor. These extensions are called Bundles.

E:The E-text editor is built just like TextMate editor to work on Windows. It replicates many features of the TextMate and even allows to use the TextMate bundles.

IntelliJ IDEA:The IntelliJ IDEA is a commercial IDE made of JetBrains. Earlier, it was also used for Java development. JetBrains version 7.0 has added Rails support to the IntelliJ IDEA.

NetBeans:The NetBeans is an IDE from Sun. Earlier, it was used for Java development. Sun version 7.0 has added Rails support to the NetBeans.

Eclipse:The Eclipse IDE is the most commonly used IDE today. Using a plug-in RadRails, you can add Rails support entirely to the Eclipse environment.

Heroku:The Heroku IDE provides a new and unique way of writing Rails application. It is used entirely online to develop applications. You do not need to install any software on your system to use Heroku. It does not support Internet Explorer.

Aptana Studio:A product from Aptana is a stand-alone desktop IDE based on Eclipse project. It is quite similar to Eclipse. The Rails features are packaged as a plug-in to the Aptana Studio environment.

RubyMine:The RubyMine IDE is a preferable choice for Rubyists. It provides many extra features than other IDEs. One feature it includes clicks and follows. When you click on a function, it will take you to the function being called. This feature comes in handy when multiple functions share the same name and reside in different files and folder. The other features are Git annotate and Git compare.

48) What is the rail console?

The Rails console is a command line utility which runs Rails application from the command line. The Rails console is an extension of Ruby IRB. It provides all the features of IRB along with the ability to auto-load Rails application environment, including all its classes and components. It helps you to walk through your application step-by-step.

49) What are generators in ruby on rails?

The rails include code generator scripts, which are used to generate model and controller classes for an application automatically. Code generation increases your productivity when developing web applications. By running generator command, skeleton files for all your model and controller classes will be generated. It also generates database migration files for each model it generates.

50) What is a webrick web server?

Rails are configured to use WEBrick server automatically. This server is written in pure Ruby and supports almost all platforms like Windows, Mac or Unix. Alternatively, if you have Mongrel or Lighttpd server installed in your system, Rails uses either of those servers.

All the three Rails servers feature automatic reloading of code. It means, when you change your source code, you do not need to restart the server.

You may also like:

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA