Ruby on Rails interview questions – part 2

Continuing the “RoR interview questions” sequel(part one here) , these are some general Rails concepts and technologies questions. Enjoy :).

Why RoR?

0)for fast developing websites
1) DRY
2)convention over configuration
4)pure Object oriented concepts
5)less coding
6)easy understanding of coding
7)follows MVC architecture
8)using library and gem files


What is agile development? What are the strenghts?

Agile software development refers to a group of software development methodologies based on iterative development, where requirements and solutions evolve through collaboration between self-organizing cross-functional teams


  • Customer satisfaction by rapid, continuous delivery of useful software
  • Working software is delivered frequently (weeks rather than months)
  • Projects are built around motivated individuals, who should be trusted
  • Continuous attention to technical excellence and good design
  • Simplicity
  • Self-organizing teams
  • Regular adaptation to changing circumstances

What is MVC? Explain each element.

Name some of the the new features that Rails 2.0, 2.1, 2.3 brings.

Model Questions

What can you define in model?

1. Validations (like validates_presence_of, numeracility_of, format_of etc.)
2. Relationships(like has_one, has_many, HABTM etc.)
3. Callbacks(like before_save, after_save, before_create etc.)
4. Suppose you installed a plugin say validation_group, So you can also define validation_group settings in your model
5. ROR Queries in Sql

(answer from:

What is ActiveRecord? What is ORM?

Model relationships

  • belongs_to
  • has_one
  • has_many
  • has_many :through

A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model

  • has_one :through
  • has_and_belongs_to_many

What is the difference between has_one and belongs_to?

The distinction is in where you place the foreign key (it goes on the table for the class declaring the belongs_to association), but you should give some thought to the actual meaning of the data as well. The has_one relationship says that one of something is yours – that is, that something points back to you. For example, it makes more sense to say that a supplier owns an account than that an account owns a supplie

Model Validations

What is validates_associated?

Validates whether the associated object or objects are all valid themselves. Works with any kind of association.

Model callbacks

Callbacks are hooks into the lifecycle of an Active Record object that allow you to trigger logic before or after an alteration of the object state. This can be used to make sure that associated and dependent objects are deleted when destroy is called (by overwriting before_destroy) or to massage attributes before they‘re validated (by overwriting before_validation)

What is the difference between save and save! ?

Save! performs all validations and callbacks. If any validation returns false, save! throws an error and canceles the save.
Save does not throw any error in the case above, but canceles the save. Also, the validators can be bypassed.

Related objects newly created. When are they saved?

When you assign an object to a has_many association, that object is automatically saved (in order to update its foreign key). If you assign multiple objects in one statement, then they are all saved.

If any of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.

If the parent object (the one declaring the has_many association) is unsaved (that is, new_record? returns true) then the child objects are not saved when they are added. All unsaved members of the association will automatically be saved when the parent is saved.

If you want to assign an object to a has_many association without saving the object, use the method.

Model relationships? How is “has_and_belongs_to_many” implemented in the database?

A. Polymorphic associations

belongs_to :imageable, :polymorphic => true

has_many :pictures, :as => :imageable

has_many :pictures, :as => :imageable

B. Self joins

What is the difference between delete and destroy?

Delete removes the association, destroy removes also the associated record from the DB.


What are the types of routes that can be declared in routes.rb?

What are REST routes?

CRUD rest routes (for map.resources :photos):

HTTP vb URL controller action used for
GET /photos Photos index display a list of all photos
GET /photos/new Photos new return an HTML form for creating a new photo
POST /photos Photos create create a new photo
GET /photos/1 Photos show display a specific photo
GET /photos/1/edit Photos edit return an HTML form for editing a photo
PUT /photos/1 Photos update update a specific photo
DELETE /photos/1 Photos destroy delete a specific photo

What is the difference between photos_url and photos_path?

photos_url # => ""

photos_path # => "/photos"

What are filters? and how many types of filters are there in ruby?

Filters are methods that are run before, after or “around” a controller action.

Filters are inherited, so if you set a filter on ApplicationController, it will be run on every controller in your application.

Filter can take one of three forms: method reference (symbol), external class, or inline method (proc).

What is the flash?

The flash is a special part of the session which is cleared with each request. This means that values stored there will only be available in the next request, which is useful for storing error messages etc. It is accessed in much the same way as the session, like a hash.

What is the h function? Against what kinds of attacks can it help?


What are helpers? What can you put in a helper?

From where can the methods in a helper be accessed?


How are the errors displayed in the view?

error_messages and error_messages_for

Difference between form_for and form_tag

What is a .rjs file? Why do we use request.xhr? in rails

What is REST?

Rails caching strategies

Rails cache sweepers

Sweepers are the terminators of the caching world and responsible for expiring caches when model objects change. They do this by being half-observers, half-filters and implementing callbacks for both roles.


What are Rails plugins? Give example (comment) on some plugins you have used.

Rails Middleware

What is Rails Rack?

What is Rails Metal?


2 Responses

  1. […] […]

  2. Hi,

    These are very awesome. Very helps to me.

    Thank you.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: