Lucas White

Full Stack Engineer

Some fun facts about Ruby on Rails

Ruby on Rails is open-source software, so it is free to use, plus any developer can contribute to improving it. Its first release was on 13 December 2005. Several popular applications, such as Basecamp, Airbnb, and SoundCloud. The emergence of Ruby on Rails in the 2000s contributed a lot to the web development domain, with innovative features like seamless database table creations, migrations, and scaffolding of views to enable rapid application development.

Ruby on Rails interview questions.

Technology is revolutionizing at a rapid pace. This decade has witnessed a boom in technology. New fields such as digital marketing, web and app development, and graphic design, have flourished and taken over many traditional job profiles. With the advent of remote work and freelancing, the number of employees in the workforce is expanding like anything.

Here I present to you some very important and awesome Ruby on Rails interview questions of 2019. You should go through each one of them and assess each question and answer.

Q1. What exactly do you know about Ruby on Rails and how well can it be defined?

Answer: It is a server-side framework for web applications that is widely regarded as one of the best in every aspect. It is a combination of Python and therefore it is easy to use. Also, there are various abilities of the Smalltalk, as well as Perl which is combined in the framework. This makes it one of the trusted approaches. It is a high-level programming language with a high scope in the present and being an object-oriented approach, developers consider it for building large scale projects.

Q2. Why and how did ROR become popular and successful?

Answer: It is an open-source approach with license needs not very complex. The Ruby on Rails has rich libraries which simply make sure that users get a diverse array of support without worrying about anything. It is easy to learn and can simply be trusted for coming out with large scale projects without having a dependency on third-party approaches. The users can always make sure of less coding and with a very limited number of bugs that one can easily avoid. The extensible nature and the true object-oriented approach have also contributed to its success and popularity.

Q3. Define scaffolding and what sort of advantages does Ruby offer when it comes to the same?

Answer: During project development, the user has to frequently write codes in the early stage of development. These codes help to build the application in a very quick and reliable manner and also, a close eye can be kept on the working of major components with this approach. Ruby does the scaffolding automatically and the users are free to concentrate on the core development only from the first day of development.

Q4. Find and fix the issue in the controller code written below.

class CommentsController < ApplicationController
  def users_comments
    Posts = Post.all
    comments =
    @user_comments = do |comment| == params[:username]

Answer: This is a classic example of the notorious “n+1” bug. The first line will retrieve all of the
Post objects from the database, but then the very next line will make an additional request for each
each Post to retrieve the corresponding Comment objects. To make thing worse, the code is then making even more database requests to retrieve the Author of each Comment.

You can avoid all of this by changing the first line on the method to:

posts = Post.includes(comments: [:author]).all

This tells ActiveRecord to retrieve the corresponding Comment and Author records for the database immediately after the initial requests for all Posts, therefore reducing the number of database requests to just three.

Q5. What is CSRF?

Answer: CSRF stands for Cross-Site Request Forgery. This is a form of an attack where the attacker submits a form on your behalf to a different website, potentially causing damage or reveal sensitive information. Since browsers will automatically include cookies for a domain on a request, if you were recently logged in to the target site, the attacker’s request will appear to come from you as a logged-in user.

Q6. How does Ruby on Rails use the Model View Controller (MVC) framework?

Answer: Web development is divided into three separate but closely integrated subsystems:

Model (Active Record): The model handles all the data logic of the application. In Rails, the Active Record library forms the bridge between the Ruby program code and the relational database.
View (Action View): The view is the part of the application that the end-user sees. In Rails, this is implemented by the Action View library, which is based on Embedded Ruby (ERB) and determines how data is presented.
Controller (Controller Action): The controller is like a data broker of an application, handling the logic that allows the model and view to communicate with one another. This is the Action Controller in Rails.

Q7. What is the use of garbage collection in Ruby on Rails?

Answer: Generally, garbage collection frees up memory for other processes by removing pointer programs and inaccessible objects left behind after a program executes. This frees the programmer from having to track objects created dynamically during runtime.

Q8. Given an array [1,2,3,4,5,6,7,8,9], sum it up using a method.

Answer: Summation of an array is one of the most fundamental concepts in programming, and there are a lot of methods to achieve it, such as iterating the array and summing the numbers. In Ruby, it’s neat to know that we can call inject, because it’s so powerful yet simple.

def sum(array)
  return array.inject(:+)

Q9. What is metaprogramming?

Answer: Ruby developers should know what metaprogramming is because it is popular, especially in frameworks like Rails, Sinatra, and Padrino. By using metaprogramming, we can reduce duplicate code, but there is a downside where it will increase the complexity of the code in the long run.

Q10. What is wrong with the code below? Also, state the reason.

require "benchmark"
puts Benchmark.measure do
    break if Random.rand(100) === 1 while true

Answer: The operator precedence is the issue in the code. The code will return:

LocalJumpError: no block given (yield)

As do-end is weaker than attracting arguments to the function, that’s why one either needs to surround the whole call to Benchmark.measurewith parentheses, or to use curly brackets instead of do-end.

Q11. Give some uses and examples of Ruby modules

  • Traits/Mixins: It is a useful alternative to class inheritance when there is a need to acquire behavior that describes a trait instead of an is-a relationship, especially when there is a need for multiple traits since a class can only inherit once. Examples include mappable, renderable, and movable.
  • Namespace: Namespace Ruby classes and modules to avoid naming clashes with similarly-named classes/modules from libraries. Examples include finance, graphics, and devise.
  • Singleton class alternative: You cannot instantiate modules, therefore you can use them as easy alternatives to Singleton classes to represent only one instance of a domain model via module methods (the equivalent of class methods). Examples include application, universe, and game.
  • Bag of stateless helper methods: Stateless helper methods receive their data via arguments without the need of a class to be instantiated nor keep any state (e.g. calculate_interest(amount, rate_per_year, period), so a module is used instead of holding a bag of stateless helper methods.

In addition to this, it is crucial to know when to use a module v/s a superclass when doing object-oriented domain modeling since that can greatly impact maintenance of a code a few months down the road in a software project.

I hope you read and understood all the questions given above.

Check out the profiles of highly talented and top Ruby on Rails developers and coders here.

How useful was this post?

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Please do Rate Us and Share!

Related Blogs

  • author
    Adam Davidson

    Best Android Emulator for PC

    Android emulator for PC or MACs is one of the best for gamers to focus and improve their gaming skills.There are many reasons for emulating Android on your Windows PC, because with the help of emulation it is much easier to test apps on-screen or desktop than a mobile device. Android developers can debug...

  • author
    Adam Davidson

    Companies that Use Node JS in Production

    Despite of being arrived late on the scene, NodeJS is dominating the entire application development scenario with its great optimal features. This is a well-kept secret for the seamless distribution of their services that some of the top companies that use NodeJS for its web-based applications today. From concurrence to being a lightweight runtime,...

  • author
    Lucas White

    How to Use callBack With setState in React

    Today we are going to explore the callback function in setState and get to know about how we can use it.  First of all, I’d like to explain the ‘callBack’ and ‘setState’. callBack functions is a function that is passed as an argument to another function, to be “called back” at a later time....


About The Author

Lucas is a passionate software engineer with over fifteen years of experience developing software under both web and Windows environments. He specializes in Node.js and .NET frameworks, as well as React and AngularJS on the front-end. Lucas holds a Master’s degree in computer science and has worked with a variety of Agile teams. He communicates extremely well.

Try our One-Week Risk Free Trial for Hiring a Coder

Know more Hire a Coder