Ruby on Rails Developer Interview Preparation Guide
Download PDF

Ruby on Rails Developer related Frequently Asked Questions by expert members with professional career as Ruby on Rails Developer. These list of interview questions and answers will help you strengthen your technical skills, prepare for the new job interview and quickly revise your concepts

30 Ruby on Rails Developer Questions and Answers:

1 :: What is RVM?

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

2 :: What is Rails Scaffolding?

Scaffolding is a quick way to produce some major pieces of an application. For auto generating a set of models, views and controllers for a new resource in a single operation, scaffolding is used.

3 :: Explain me what Are The Components Defined In The Model From Mvc Architecture?

The components involved in defining the model are as follows:

☛ Validations: this is one of the very essential components and it defines the validations that are being put up on the input type of stream like validate_presence_of, format_of, etc.

☛ Relationship: this is another type of component that describe the relationship between different types of components and it shows the relationship in the form of has_one, has_many, etc.

☛ Callbacks: this is essential when it comes to respond after the failure and it allows the application to have certain functionality during failure. This can be given as before_save, after_save, etc.

☛ Validation group settings: allow users to define the installed plugin settings.

☛ Active record association relationship: allows current records to be actively having the relationship between one another.

4 :: Please explain request/response cycle?

Let’s explain request/response flow in Rails:

☛ The user opens their browser and enters a URL.
☛ The browser sends a GET request to the URL. The request hits the Rails Router (config/routes.rb).
☛ The router receives the request information from the web server and based on that, decides which controller action should be called. If a request matches to any path in the routes file, the corresponding controller and action will be called.
☛ The controller receives the parameters from the router and passes them into appropriate model methods.
☛ The model queries a database to fetch data.
☛ The Database returns stored data to the model.
☛ The model manages the data and returns it to the controller.
☛ The controller feeds the received data to the view.
☛ The view renders the page as HTML, prepares a response and forwards it to the controller.
☛ The controller forwards the ready response to the browser.
☛ The browser displays a response to the user.

5 :: Explain what’s different between ActiveRecord::Relation’s count, length and size methods?

☛ count – counts the number of elements using query with the SQL command ‘COUNT’ but the result is not stored internally during object life cycle. This means, each time we invoke this method, SQL query is performed again. You should use this method if you don’t have anything loaded.
☛ length – loads all objects just to count them and then return the result count. It should be used only if you have already loaded all entries to avoid another database query.
☛ size – returns the size of the collection. If a collection is loaded, it will count its elements without any database query; but if a collection is not loaded, it will perform an additional query.
So we can say that size adapts to the situation.

6 :: Tell me how does Rails implement AJAX?

Asynchronous JavaScript and XML (AJAX) is a suite of technologies used to retrieve data for a webpage without having to refresh the page itself. This is how modern websites are able to cultivate a “desktop-like” user experience. The Rails method of implementing AJAX operations is short and simple.

☛ First, a trigger is fired. The trigger can be something as simple as a user clicking on a call to action.
☛ Next, the web client uses JavaScript to send data via an XMLHttpRequest from the trigger to an action handler on the server.
☛ On the server-side, a Rails controller action receives the data and returns the corresponding HTML fragment to the client.
☛ The client receives the fragment and updates the view accordingly.

7 :: Do you know the role of garbage collection in Ruby on Rails?

Garbage collection frees up memory for other processes by removing pointer programs and inaccessible objects left behind after a program has executed. This frees the programmer from having to track objects created dynamically during runtime.

8 :: What is Rails Migrations?

Migrations are a way to alter database schema over time in a consistent and organized manner. They use a Ruby DSL through which there is no need to write SQL by hand.

9 :: Tell us what Is Active Record?

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

10 :: Tell us what Is The Log That Has To Seen To Check For An Error In Ruby Rails?

Rails will report errors from Apache in log/apache.log and errors from the ruby code in log/development.log. If you having a problem, do have a look at what these log are saying.