Ruby on Rails or Rails is a model-view-controller, server-side framework which is written in ruby. It provides a default structure for a database, web service and web pages. It makes use of web standards like JSON, XML, HTML, CSS, etc. for the transfer of data and also for displaying and user interfacing. It was developed by David Heinemeier Hansson on 13th December 2005. It even uses various software engineering patterns and paradigms some of them being- Convention over configuration (CoC), Don’t Repeat Yourself (DRY), and Active Record Pattern (ARP). It had a great influence on web development since it had some innovative features and frameworks.

Read Top Ruby on Rails Interview Questions and Answers

Following are some interview questions for the ruby on rails framework.

Ruby on Rails Interview Questions

1) Mention all the naming conventions in ruby on rails.

Following is a list of some naming conventions used in ruby on rails:
  • Variables– it is used for the declaration of variables in which all the letters should be in lowercase and the words should be separated by underscore.
  • Class and module– a class is declared which encapsulates every function. The class or module name can be written in mixed case and no underscores are used. Every word should start with an uppercase letter.
  • Database table– a table is made for storing the data. It is the same as the naming conventions for variables.
  • Model– mixed case is used and have singular with table name.
  • Controller– names are represented in plural form.

2) Explain the features of ruby on rails.

Some of the features of ruby on rails are listed below-
  • Meta-programming: code generation is used but for heavy lifting, it uses meta-programming.
  • Active record: objects are saved to the database through this framework. It identifies the columns in a schema and binds them to your domain object.
  • Scaffolding: it means it has the ability of creating temporary code automatically.
  • Convention over configuration: much configuration is not needed if the naming convention is followed.
  • Three environments: testing, development, and production are the three default environments in this framework.
  • Built-in testing: test cases are used in this for writing and executing the codes.

3) How is the model view controller framework used in ruby on rails?

The web development is usually divided into three subsystems closely integrated to each other. They are: –
  • Model (active record): all the data logic is handled by this model which in rails is known as the active record library. It acts a bridge between the ruby program code and the main database.
  • View (action view): the end user sees the view part of the application.
  • Controller (action controller): it acts as a data broker of an application. It also helps in handling the logic which allows the model and view to communicate with one another.

This is how the model view controller framework used in ruby on rails.

4) What do you understand by rails?

It is a web application framework which is written in ruby language and is developed by David Hansson. It is an open source ruby framework for the development of database backend web application. It consists of everything which is needed for creating a database driven web application with the help of model view controller pattern.

5) What are the different filters used in ruby on rails?

The methods which are used before and after the action of the controller method are executed. It ensures that the code runs with the given action method which is called. Three types of filters are supported by rails. They are:
  • Before filters: these filters are executed before the execution of the code in the action controller.
  • After filters: these filters are executed after the execution of the code in the action controller.
  • Around filters: these are executed both before and after the execution of the code present in the action controller.

6) How can the filter methods in ruby on rails be protected?

Some of the methods are listed below which are used for the protection of filters: –
  • Public: any external class or method that uses the same class in which it is defined can access this method.
  • Protected: these can be used only within the class in which they are defined and the classes that inherit from the class in which they are defined.
  • Private: these can be accessed only within the class in which they are defined.

7) Explain the role of sub directory app/controllers and app/helpers.

  • App/controllers: in this, a web request is made by the user which is handled by the controller. Rails make use of this controller sub directory for finding the controller class.
  • App/helpers: some helper classes are present in the helper sub directory which is used for assisting the view, model and the controller classes present in it.

8) What do you understand by rails migration and what it can do?

With the help of rails migration, we can make changes in the database schema which makes it possible to use the version control system for synchronization of those things with the actual code. Rails migration can perform the following things:
  • It helps in creating the table for the database.
  • Dropping the table is possible with the help of this.
  • Renaming of the table is possible.
  • We can even add columns.
  • Renaming of the columns can be done.
  • Columns can be changed too.
  • We can remove the columns and various other things can be done.

9) Mention the role of rails controller.

The rails controller works as the main logical centre of the application. With the help of this user, views, and models can interact with each other. Routing of external requests to internal actions is possible. It can handle the URL very well. It helps in regulating helper modules which extends the capabilities of view templates. It also regulates the session which gives user an impression of an on-going interaction with any application.

10) Mention the differences between the observers and callbacks in ruby on rails.

Following are the differences between observers and callbacks in ruby on rails: –
  • Rails observers: these are same as callbacks but are used when the method is not directly associated to the life cycle of the object. It lives for a longer duration of time and can be attached or detached at any time.
  • Rails callback: the callback methods can only be called at only certain points of time in the life cycle of an object like validation, creation, updating, deletion, etc. Unlike the rails observers, the rails callback lives for only a short period of time.

Leave A Comment :

Valid name is required.

Valid name is required.

Valid email id is required.

Related Interview Questions