Skip to main content

ROR Interview

1.    Tell us something about yourself, and how your career growth has been.
2.    When did your degree commenced?
3.    Tell us something about your work experience.
4.    What is the architecture of rails?
5.    What can we use ‘runner’ for in Ruby on Rails, and where is it present?
6.    What is the structure of Model?
7.    What are filters in models and how do we use them?
8.    What are callbacks in models?
9.    What are helpers?
10.   Differentiate between include and join.
11.   How would you define validation for a field not present in the table for a model?
12.   How can you run validation using a helper defined in the model?
13.   What are layouts?
14.   What are yields (please define)?
15.   Can yields only be used in views?
16.   Is yield a helper introduced by rails or is it a ruby feature?
17.   Say there are 4 methods in a model: pending, progress, disable and enable. Now, there is a common url for a common controller and action for all four, say ‘default_controller’ and ‘change_status’ with parameter named :status. How will you call corresponding method in model from inside the default_controller?
18.   How can you render a collection of objects without using loop statement in ruby?
19.   What are the advantages you noticed in Ruby over the programming language(s) you’ve worked in the past?
20.   What is the use of methods ‘send’ and ‘send_data’ and how are they different?
21.   How well do you rate yourself in Ruby, Rails, AJAX & object-oriented javascript?
22.   What are callbacks?
23.   Are there any callbacks available for controllers?
24.   What are the callbacks available for models?
25.   What are polymorphic associations? Give a detailed example of polymorphic association with model associations.
26.   What is the use of ‘class_name’ in defining an association?
27.   What is the use of ‘through’ while defining associations?
28.   How would you link three tables using ActiveRecord and joins?
29.   What is the base class for models?
30.   What is the use or advantage of alias_method_chain in ruby?
31.   How do you validate the uniqueness of an attribute for multiple entries in the table via model?
32.   How do you make it unique among different column say ‘user_id’ in the table
33.   Does ruby support thread class, and multithreading?
34.   What is the difference between *.html.erb and *.erb files?
35.   Differentiate between flash and session.
36.   Differentiate between symbols and string?
37.   Explain method visibilities (public, private, protected).
38.   What is ‘method_missing’ used for?
39.   Differentiate between session and cookies?
40.   Differentiate between has_many and has_and_belongs_to_many
41.   Does ruby supports overloading? Give reason to support your answer.
42.   How does find_by works?
43.   How do dynamic methods get generated when you add attribute names to ‘find_by_*’ ?
44.   What is metaprogramming in ruby on rails? Give examples.
45.   Differentiate between HTTP and HTTPS.
46.   Explain a request cycle in rails.
47.   What are ruby blocks? How do they work with yield?
48.   What is the difference between Proc and block?
49.   Differentiate between attr_accessor, attr_writer & attr_reader, attr_protected.
50.   What is cattr_accessor used for?
51.   What can we used eval for?
52.   Tell us something about the scope of a variable in a class, module, helper and a function in rails.
53.   class_instance_variable… what is it?
54.   What is the difference and /or similarities between Proc and lambda ?
55.   How do you specify extra resource with plugin search?
56.   What is activesupport?
57.   What is map.resource and how is it different than map.resources?
58.   Which version(s) of rails have you worked with?
59.   What are sessions?
60.   How would you maintain a session in the architecture having a multi-instances application running on same database?
61.   What are joins? Explain LEFT OUTER JOIN.
62.   How do you use load and require? Differentiate between them.
63.   How can you manipulate and resize images in rails?
64.   How do you destroy a rails session?
65.   Differentiate between class and module.
66.   While specifying an around_filter which two methods you must extend, name them?
67.   How do we specify inheritance in ruby on rails?
68.   Which design pattern does Rails follow and is built upon?
69.   How do you specify child resources?
70.   Differentiate between - map.resource, map.resources and map.connect?
71.   How are session management implemented in rails website?
72.   Write ruby code to generate Fibonacci series of given length.
73.   Write ruby code for displaying the ‘only’ unique element (one that is occurring only once) in an array of numbers, where others are repeated atleast twice.
74.   Tell us something about your current application (xomad).
75.   How much do you rate yourself in Ruby and Rails?
76.   What is Ruby on Rails, tell briefly?
77.   Why did you switch to Ruby on Rails?
78.   What are form helpers? How many are there?
79.   Differentiate between ‘form_for’ and ‘remote_form_for’
80.   What is an index in mysql?
81.   What is the difference between prototype and jQuery?
82.   What is unobstrusive?
83.   What are associations? How many are there?
84.   How good are you designing databases?
85.   How many types of caching are there in rails?
86.   Where are cached files stored in an rails application?
87.   If you have used a file management library/plugin, which one(s) you worked with?
88.   Where does your application store files data?
89.   If you store file data in public directory, how would you avoid accessibility of original files through their complete path in the URL if you’re using paperclip?
90.   What is testing in rails? Name and give examples of it’s different types.




Overview of Ruby programming language.

    An open source programming language that focuses on simplicity and productivity. The syntax of Ruby language is elegant which is natural to read and easy to write. Ruby is well known as language of careful balance. It has the blended features of Perl, Small talk, Eiffel, Ada and Lisp................

What is Rails?

    Ruby on Rails is an open source web application framework for the Ruby programming language............

Describe class libraries in Ruby.

    The Ruby standard library extends the foundation of the Ruby built-in library with classes and abstractions for a variety of programming needs, including network programming, operating system services, threads, and more............

Explain the concepts and capabilities of garbage collection feature of Ruby.

    Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program.............

Describe the environment variables present in Ruby.


Interpolation is a very important process in Ruby, comment.

    Interpolation is the process of inserting a string into a literal..............

What is the use of super in Ruby Rails?

    Ruby uses the super keyword to call the superclass implementation of the current method.............

What is the use of load and require in ruby?

    Reuire() loads and processes the Ruby code from a separate file, including whatever classes, modules, methods, and constants are in that file into the current scope..............

Explain the use of global variable $ in Ruby.

    If you declare one variable as global we can access any where, where as class variable.............

Explain the difference between nil and false in ruby.

    False is a boolean datatype
    Nil is not a data type..............


  In Ruby, you can in double quoted strings interpolate. For example:

    "1 + 2 = #{1 + 2}" # "1 + 2 = 3"
    '1 + 2 = #{1 + 2}' # "1 + 2 = \#{1 + 2}"

     Concatenation—Returns a new String containing other_str concatenated to str.
     "Hello from " + self.to_s   #=> "Hello from main"

     Append—Concatenates the given object to str. If the object is a Integer, it is considered as a codepoint,    and is converted to a character before concatenation.

    a = "hello "
    a << "world"   #=> "hello world"
    a.concat(33)   #=> "hello world!"
-------- Require & Load------

    The load method is almost like the require method except it doesn’t keep track of whether or not that library has been loaded. So it’s possible to load a library multiple times and also when using the load method you must specify the “.rb” extension of the library file name.
        i.e load mothod load the file in muliple times

    The require method allows you to load a library and prevents it from being loaded more than once. The require method will return ‘false’ if you try to load the same library after the first time. The require method only needs to be used if library you are loading is defined in a separate file, which is usually the case.

    A subclass, heir class, or child class is a modular, derivative class that inherits one or more properties from another class (called the superclass, base class, or parent class). The properties in question vary from language to language, but commonly include class data variables, properties, and methods or functions

         i.e  the current class get the properties of another class
----------Multiple inheritence---

        ruby doesn't support Multiple inheritence but using Modules(i.e MIXINS) it is possible

-----------Include vs Extend-----

      Include- it includes the All intance methods of Module
      Extend -- it includes the All Class methods of Module
              module Logging
            def logger
            @@logger ||=
        class Person
            include Logging
            def relocate
            Person.logger.debug "Relocating person..."
            # could also access it with this
            self.class.logger.debug "Relocating person..."

               module Logging
            def logger
            @@logger ||=
        class Person
            extend Logging
            def relocate
            Person.logger.debug "Relocating person..."
            # could also access it with this
            self.class.logger.debug "Relocating person..."

----------Polymorphic associations -------

     Polymorphic associations allow us to associate a single attribute of the class to any number of specified classes. Here are the Page, HtmlAdvertisement, and ImageAdvertisement models:

    class Page  true
    class HtmlAdvertisement  :advertisement
    class ImageAdvertisement  :advertisement

       Pretty simple example, but you’re probably wondering how this works in the database. After all, an attribute of advertisement_id won’t cut it as both the image_advertisements table and the html_advertisements table will both start their id’s at 0 and don’t reference each other when incrementing.

Ruby on Rails provides you with many session storage option.


CookieStore is available only in edge rails. PStore is the default option for stable release, whereas its CookieStore as default for edge rails.
--------------Caching -----------

         caching means to store information that is repeatedly accessed so that (typically) a database does not need to be queried over and over for the same information.

         Ruby on Rails comes with page, action, and fragment caching built-in. You can use these techniques on single pages or in combinations across the pages of your application

      Page Caching and Fragment Caching
         Page caching happens when you tell Rails to cache an entire page of a website.

 Fragment caching is a bit more involved, and less efficient since it still requires Rails to get involved.
         Fragment caching is simple to learn but can be very complicated to apply.


   Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby.By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call.

-------------What is ActiveRecord?----

          Active Record is the base for the models in a Rails application. It provides database independence, basic CRUD functionality, advanced finding capabilities, and the ability to relate models to one another, among other services.

          ActiveRecord is the Ruby implementation of the Active Record pattern. The code for ActiveRecord lives in the ActiveRecord module. This module contains the classes you need to build a database and to both read from and write to that database.
          ActiveRecord is designed to be database independent.

          AR is an object combining both O/R mapping logic and domain logic.

          It provides validation functionality as well which helps keep data in the database clean. ActiveRecord also pertains to the model part of the MVC

                :adapter => "mysql",
                :host => "localhost",
                :username => "root",
                :database => "cricket_development")

-----------------Active Model-----

    Active Model provides a defined interface between the Action Pack gem services and Object Relationship Mapping gems such as Active Record. Active Model allows Rails to utilize other ORM frameworks in place of Active Record if your application needs this.


        The AbstractController is a class inside Rails which serves as a base for every controller. Your ApplicationController derives from it.

-----------How can you use multiple database in sigle rails application

    Here is my database.yml:

      adapter: mysql2
      database: se_development
      username: root
      pool: 5
      timeout: 5000

      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000

    Here is the model:

    class Plot < ActiveRecord::Base
      establish_connection 'sqlite_' + Rails.env

-------------- Difference between form_for and form_tag

        form_tag and form_for both are used to submit the form and it’s elements. The main difference between these two is the way of managing objects related to that particular model is different.


    We should use “form_for” tag for a specific model i.e. while crating a new row in database. It performs the “standard http post” which is having fields related to active record (model) objects.

    Example for how to use form_for tag:

    <% form_for :user, @user, :url => { :action => "update" } do |f| %>

    After this, we can use the f as an object to create input filed.

    Username: <%= f.text_field :username %>
    Email : <%= f.text_field :email %>
    Address: <%= f.text_area :address %>

    <% end %>


    It creates a form as a normal form. form_tag also performs the “standard http post” without any model backed and has normal fields. This is mainly used when specific data need to be submitted via form.


    <% form_tag '/articles' do -%>
    <%= text_field_tag "article", "firstname" %>
    <% end -%>

    It just creates a form tag and it is best used for non-model forms.

------------------What is Nested Resources

        It’s common to have resources that are logically children of other resources
        class Magazine < ActiveRecord::Base
      has_many :ads

    class Ad < ActiveRecord::Base
      belongs_to :magazine

        resources :magazines do
      resources :ads
-------------------What is a helper?-----

    Helpers are basically small snippets of code that can be called in your views to help keep your code DRY - i.e. Any code that you are repeating regularly can most likely be moved into a helper.

    Using helpers is simple, each controller has it's own helper file or you can write helpers in the application helper file if it will be used across the entire application. For example a pagination helper might go in there.

       def my_helper
      some code

    You can then use it in your view with:

    <%= my_helper %>

-----------------What are form helpers? How many are there?

        Forms in web applications are an essential interface for user input.

         1.The most basic form helper is form_tag
                   <%= form_tag do %>
            Form contents
           <% end %>
             The form_tag helper accepts 2 arguments: the path for the action and an options hash
             form_tag(:controller => "people", :action => "search", :method => "get", :class => "nifty_form")
             Helpers for Generating Form Elements
                <%= radio_button_tag(:age, "child") %>
                <%= text_area_tag(:message, "Hi, nice site", :size => "24x6") %>
        <%= password_field_tag(:password) %>
        <%= hidden_field_tag(:parent_id, "5") %>
        <%= search_field(:user, :name) %>
        <%= telephone_field(:user, :phone) %>
        <%= url_field(:user, :homepage) %>
        <%= email_field(:user, :address) %>
                The name passed to form_for controls the key used in params to access the form’s values

                <%= form_for @person, :url => { :action => "create" } do |person_form| %>
          <%= person_form.text_field :name %>
          <%= fields_for @person.contact_detail do |contact_details_form| %>
            <%= contact_details_form.text_field :phone_number %>
          <% end %>
        <% end %>

------------ What things we can define in the model? ----
         There are lot of things you can define in models few are:
        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

-------------Why Use Validations?

         Validations are used to ensure that only valid data is saved into your database. For example, it may be important to your application to ensure that every user provides a valid email address and mailing address.

      Validation Helpers
                 class Person < ActiveRecord::Base
          validates :terms_of_service, :acceptance => { :accept => 'yes' }
                   class Person < ActiveRecord::Base
            validates :email, :confirmation => true

          In your view template you could use something like
          <%= text_field :person, :email %>
          <%= text_field :person, :email_confirmation %>
                   class Product < ActiveRecord::Base
              validates :legacy_code, :format => { :with => /\A[a-zA-Z]+\z/,
                :message => "Only letters allowed" }
                class Person < ActiveRecord::Base
          validates :name, :length => { :minimum => 2 }
          validates :bio, :length => { :maximum => 500 }
          validates :password, :length => { :in => 6..20 }
          validates :registration_number, :length => { :is => 6 }

        The possible length constraint options are:

            :minimum – The attribute cannot have less than the specified length.
            :maximum – The attribute cannot have more than the specified length.
            :in (or :within) – The attribute length must be included in a given interval. The value for this option must be a range.
            :is – The attribute length must be equal to the given value.
                class Player < ActiveRecord::Base
          validates :points, :numericality => true
          validates :games_played, :numericality => { :only_integer => true }
               class Person < ActiveRecord::Base
          validates :name, :login, :email, :presence => true
                class Account < ActiveRecord::Base
          validates :email, :uniqueness => true

        This helper passes the record to a separate class for validation.
        class Person < ActiveRecord::Base
          validates_with GoodnessValidator

        class GoodnessValidator < ActiveModel::Validator
          def validate(record)
            if record.first_name == "Evil"
              record.errors[:base] << "This person is evil"
                class Person < ActiveRecord::Base
          validates_each :name, :surname do |record, attr, value|
            record.errors.add(attr, 'must start with upper case') if value =~ /\A[a-z]/
     Common Validation Options

                 :allow_nil,:allow_blank,:on ,:message

    Conditional Validation
          :if ,:unless
               class Order < ActiveRecord::Base
          validates :card_number, :presence => true, :if => :paid_with_card?

          def paid_with_card?
            payment_type == "card"
----------Tell us the changes between the Rails version 2 and 3?

         (1) Introduction of bundler (New way to manage your gem dependencies)
     (2) Gemfile and Gemfile.lock (Where all your gem dependencies lies, instead of environment.rb)
     (3) A new .rb file in config/ folder, named as application.rb (Which has everything that previously environment.rb had)
     (4) Change in SQL Structure: Model.where(:activated => true)
     (5) All the mailer script will now be in app/mailers folder, earlier we kept inside app/models.
     (6) Rails3-UJS support. for links and forms to work as AJAX, instead of writing complex lines of code, we write :remote => true
     (7) HTML 5 support.
     (8) Changes in the model based validation syntax: validates :name, :presence => true
     (9) Ability to install windows/ruby/jruby/development/production specific gems to Gemfile.
    group :production do
    gem 'will_paginate'
                      ------------- Questions------------

Q21. What is bundler?
Sol: Bundler is a new concept introduced in Rails3, which helps to you manage your gems for the application. After specifying gems in your Gemfile, you need to do a bundle install. If the gem is available in the system, bundle will use that else it will pick up from the

Q22. What is the Newest approach for find(:all) in Rails 3?
Sol: Model.where(:activated => true)

Q23. What is Gemfile and Gemfile.lock?

Ruby Interview Questions :

Q1. What is the Notation used for denoting class variables in Ruby?

Q2. What is the use of Destructive Method?

Q3. What is the use of load and require in Ruby?

Q4. What is the use of Global Variable in Ruby?

Q5. How does nil and false differ?

Q6. How is visibility of methods change in Ruby?

Q7. What is a Class Instance Variable

Q8. What are the rules and conventions to be followed in Ruby for naming a method?

Q9. What is the use of Super?

Q10. How is class method defined in Ruby?

Q11. What are the Operators available in Ruby?

Q12. What are the looping structure available in Ruby?

Q13. What is the scope of local variable?

Q14. What are the OOP supported by Ruby?

Q15. If Ruby over PHP, Why?

Q16. Garbage collection in Ruby?

Q17. Environment Variables in Ruby?

Q18. What are Float, Dig and Max?

Q19. What is Ruby Code blocks?

Q20. What kind of conditions ruby support?

Q21. Difference between puts and print

Some More Questions are here:
Q1. What is Agile methodology? What are their Processes?

Q2. Is there any technology apart from agile which we can use?

Q3. What are the servers supported by ruby on rails application?

Q4. What is new in Rails 3.0?

Q5. What is Meta-programming? How you are using it inside your rails application?


Q6. What is has_many?
Ans. It is a way of defining relationships among models. Correct, and Do you guys really know has_many is also an example of Meta-programming? Wondering, How?

Q7. What is TDD and BDD?
Hint: Test-Driven-Development and Behavior-Driven-Development

Q8. What is rspec, cucumber and Watir? And what it has to do with TDD and BDD ------------ video chating and other intigrations


Popular posts from this blog

Get user accessing ip address in rails?

Get user accessing ip address rails?

request.ip ->returns the ip, whether is is a local proxy ip (localhost address) or not.
*request.remote_ip -> is smarter and gets the ip address of the client outside of local proxies.
3)If you are using apache in front of a mongrel, then remote_ip will return the source address of the request, which in this case will be local host because the Apache web server is making the request, so instead put this in your controller:

@remote_ip = request.env["HTTP_X_FORWARDED_FOR"]

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?

1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

PayUMoney Integration in Ruby on Rails

PayUMoney Integration in Ruby on Rails

Generating Cheksum in Payu
   Hash or Checksum
= sha512(key|txnid|amount|productinfo|firstname|email|u

Controller Code Will be
def payumoney
  @key = "gtKFFx"
  @salt =  "eCwWELxi"
  val = "#{key|txnid|amount|productinfo|firstname|email|u
 @checksum = Digest::SHA512.hexdigest("#{val}")

<form action="" method='post' id='sub'  >
    <input type="hidden" name="key" value="<%=@key%>">
    <input type="hidden" name="hash" value="<%=@checksum%>">
    <input type="hidden" name="txnid" value="TXN1234">
    <input type="hidden" name="amount" value="200">
    <input type="hidden" name="firstname" value=&quo…