Ruby on Rails Interview Questions 2025

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.

.

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.

.

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.

.

5) Who developed Rails?
Ruby on Rails was created by David Heinemeier Hansson (DHH).

.

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
.

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
.

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
.

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.

.

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.

.

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.

.

14) Which command is used to create a migration?
C:\ruby\application>ruby script/generate migration table_name


15) Explain the role of ‘defined’ operator.

The ‘defined’ operator is used to check whether the expression passed has been defined or not.


16) What is the purpose of the super call?

When we make a call to super, the parent method which has the same arguments as child one is invoked.


17) Write the syntax of each iterator.

The syntax of each iterator is <br /> collection.each do|vairable| <br /> code <br /> end <br /> 18) What are the hashes?<br /> A hash is a collection of key-value pairs.</p> <p>19) How are blocks created?<br /> The syntax for creation of block is:</p> <p>block_name <br /> { <br /> ??. <br /> ?? <br /> } <br /> 20) What is the naming convention for variables?<br /> The name of the variable is given in the lower case, and an underscore separates the different words within the name.</p> <p>21) What is the main difference between procs and blocks?<br /> Procs are objects whereas Blocks are a part of the code.</p> <p>22) The string can be represented in single as well as double quotes. What is the difference between the two?<br /> The single quote string representation is not allowed to perform string interpolation and process the ASCII escape codes.</p> <p>23) Explain rails migration.<br /> With the help of rails migration, Ruby can make changes to the database schema.</p> <p>24) How would you create a controller for the subject?<br /> You have to use the following command to create a controller for subject:</p> <p>C:\ruby\library> ruby script/generate controller subject <br /> 25) Explain view in Rails?<br /> 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.</p> <p>.</p> <p>26) Explain the controller in Rails?<br /> 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.</p> <p>.</p> <p>27) Explain RVM in Rails?<br /> 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.</p> <p>Syntax:</p> <p>The basic syntax of RVM is,</p> <p>rvm command_options command ruby_to_act_on <br /> .</p> <p>28) What are Gemsets in Rails?<br /> 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.</p> <p>To know all the gems available in Ruby, use the following command:</p> <p>rvm gemset list <br /> .</p> <p>29) Write the command to update RVM in Rails.<br /> To upgrade RVM, use the following command:</p> <p>rvm et head <br /> .</p> <p>30) Explain bundler in Rails.<br /> Rails bundler provides a constant environment for applications by tracking suitable gems that are needed.</p> <p>To use bundler, use the following command:</p> <p>gem install bundler <br /> .</p> <p>31) Why we use migration in Rails?<br /> Migration alters the database schema for an application in a consistent and organized manner by using DSL.</p> <p>Syntax to create a migration file:</p> <p>application_dir> rails generate migration table_name <br /> .</p> <p>32) Write the command to run the migration.<br /> rake db:migrate <br /> .</p> <p>33) How does router work in Rails?<br /> 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.</p> <p>Main purpose of Rails routers is:</p> <p>Connecting URLs to code<br /> Generating paths and URLs from code<br /> .</p> <p>34) Explain REST in Rails routes.<br /> 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.</p> <p>.</p> <p>35) Explain some features of nested scaffolding.<br /> The Nested scaffold is the command that generates a set of correctly working nested resource for Rails 4.2 and 5.</p> <p>Features</p> <p>Generates a nested child resource with a single command<br /> Generates a beautifully working bunch of code<br /> Automatically generates appropriate model associations for ActiveRecord<br /> Haml ready<br /> .</p> <p>36) In how many ways you can create Rails layout HTTP response.<br /> There are three ways to create an HTTP response from the controller’s point of view:</p> <p>Call render to create a full response to send back to the browser<br /> Call redirect_to to send an HTTP redirect status code to the browser<br /> Call head to create a response to end back to the browser<br /> .</p> <p>37) Explain the importance of yield statement in Rails.<br /> 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.</p> <p>.</p> <p>38) How many filters are there in Rails.<br /> Rails filters are methods that run before or after a controller’s action method is executed. Rails support three types of filter methods:</p> <p>Before filters<br /> After filters<br /> Around filters<br /> .</p> <p>39) Explain testing in Rails.<br /> 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.</p> <p>Rails support three types of tests:</p> <p>functional<br /> integration<br /> unit tests<br /> .</p> <p>40) How can you protect filter methods in Rails?<br /> All the Ruby methods have at least one of these protection level.</p> <p>Public: These methods are accessible from any external class or method that uses the same class in which they are defined.<br /> 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.<br /> Private: These methods are only accessible within the class in which they are defined.</p> <p>41) What are Rails validation used for?<br /> 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.</p> <p>.</p> <p>42) Explain Rails caching levels.<br /> Rails caching is available at three levels of granularity:</p> <p>Page<br /> Action<br /> Fragment<br /> .</p> <p>43) Explain valid and invalid in Rails?<br /> The valid? triggers your validations and returns true if no errors are found otherwise, false.</p> <p>The invalid? is simply the reverse of valid?. It triggers your validations and returns true if invalid otherwise, false.</p> <p>.</p> <p>44) Explain Unobtrusive JavaScript in Rails.<br /> “Unobtrusive JavaScript” technique is considered as the best technique within the frontend community.</p> <p>.</p> <p>45) What is Action Cable?<br /> 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.</p> <p>46) What is the Symbol Garbage Collector?<br /> 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.</p>


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *