What is agile development ?

Agile methodology is an adaptive methodology, its people oriented. Here are some of the other characteristics of the Agile methodology.

  1. Delivery frequently.
  2. Good ROI(Return on Investment) for client.
  3. Test frequently.
  4. Collaborative approach.

Agile methodology is on daily basis report. How much work we have completed on that day and how much work is still pending it gives the clear picture, but the requirments are not defined beforehand itself completely requirments will be changing.

Why Ruby on Rails?

There are lot of advantages of using Ruby on Rails(ROR)

  1. DRY Principle
  2. Convention over Configuration
  3. Gems and Plugins
  4. Scaffolding
  5. Pure OOP Concept

What is MVC? and how it Works?

MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like below image

MVC image

for Example your url is something like this: http://localhost:3000/users/new

here users is your controller and new is your method, there must be a file in your views/users folder named new.html.erb, so once the submit button is pressed,

User model or whatever defined in the rhtml form_for syntax, will be called and values will be stored into the database.

What is ORM in Rails?

ORM tends for Object-Relationship-Model, it means that your Classes are mapped to table in the database, and Objects are directly mapped to the rows in the table.

What is Ruby Gems?

Ruby Gem is a software package, commonly called a “gem”. Gem contains a packaged Ruby application or library. The Ruby Gems software itself allows you to easily download, install and manipulate gems on your system.

What is Gemfile and Gemfile.lock?

The Gemfile is where you specify which gems you want to use, and lets you specify which versions.

The Gemfile.lock file is where Bundler records the exact versions that were installed.

This way, when the same library/project is loaded on another machine, running bundle install will look at the Gemfile.lock and install the exact same versions, rather than just using the Gemfile and installing the most recent versions. (Running different versions on different machines could lead to broken tests, etc.) You shouldn’t ever have to directly edit the lock file.

Why Active record?

  1. There are many reasons why Active Record is the smart choice.
  2. Simplified configuration and default assumptions (Convention over Configuration).
  3. Associations among objects.
  4. Automated mapping b/w tables and classes and b/w columns and attributes.
  5. Data Validations.
  6. Callbacks.
  7. Inheritance hierarchies.
  8. Direct manipulation of data as well as schema objects.
  9. Database abstraction through adapters.
  10. Logging support.
  11. Migration support.
  12. Active Record integrated in other emerging frameworks like Merb.

What is the difference between a plugin and a gem?

A gem is just ruby code. It is installed on a machine and it’s available for all ruby applications running on that machine. Rails, rake, json, rspec — are all examples of gems.

Plugin is also ruby code but it is installed in the application folder and only available for that specific application. Sitemap-generator, etc. In general, since Rails works well with gems you will find that you would be mostly integrating with gem files and not plugins in general. Most developers release their libraries as gems.

What is restful in rails?

Stands for REpresentational State Transfer

What is passanger?

Easy and robust deployment of ruby on rails app on appache and ngix webservers passenger is an intermediate to run the ruby language in linux server.

What is request.xhr?

A request.xhr tells the controller that the new Ajax request has come, It always return TRUE or FALSE

What is the Difference between Static and Dynamic Scaffolding?

The Syntax of Static Scaffold is like this: ruby script/generate scaffold User Comment Where Comment is the model and User is your controller, So all n all static scaffold takes 2 parameter i.e your controller name and model name,

whereas in dynamic scaffolding you have to define controller and model one by one.

What is Session and Cookies?

Session: are used to store user information on the server side. e.g. Session : say session[:user] = “srikant” it remains when the browser is not closed cookies: are used to store information on the browser side or we can say client side

What is the 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.

form_for : We should use “form_for” tag for a specific model It performs the “standard http post” which is having fields related to active record (model) objects

form_tag : 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. It just creates a form tag and it is best used for non-model forms.

<% form_tag ‘/articles’ do -%>
<%= text_field_tag “article”, “firstname” %>
<% end -%>

What is the difference between include and extend?

include makes the module’s methods available to the instance of a class, while extend makes these methods available to the class itself.


When you use include, the module’s methods are added to the instances of the class. The log method is: Not available at the class level Available at the instance level Not available at the class level again

When you use extend, the module’s methods are added to the class itself. The log method is: Available at the class level. Not available at the instance level. Available at the class level.

Reference: http://ionrails.com/2009/09/19/ruby_require-vs-load-vs-include-vs-extend/ http://rubyquicktips.com/post/1133877859/include-vs-extend

What is the difference between lambada and proc?

proc and Lambda are used to create code blocks. After creating them, we can pass them around our code, just like variables.

How to call method dynamically?

[“foo”, “bar”].each do |method| MyClass.send(method) End

How to create a method dynamically?

class Message
 [:hello, :goodbye].each do |method_name|
  define_method method_name do |arg|
   “#{method_name} #{arg}”
Message.instance_methods false #=> [:hello, :goodbye]
Message.new.hello ‘emre’ #=> “hello emre”
Message.new.goodbye ‘emre’ #=> “goodbye emre”

How to use Nested routes in ROR?

The easiest way to create a nested route, is to use the :has_many keyword like that:


map.resources :projects, :has_many => :tasks

and the correspondent task resource map.resources :tasks Adding the second routes, that defines a RESTful route to :tasks, depends if you would like to allow an access to the Task resource, without the project context, this is not a must.

Reference : http://pandejo.blogspot.in/2009/03/rails-nested-resources-tutorial.html

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

How many Types of Relationships does a Model has?

  1. has_one
  2. belongs_to
  3. has_many
  4. has_many :through

What is observer in rails?

Observer classes respond to life cycle callbacks to implement trigger-like behavior outside the original class. Rails observers are sweet, You can observe multiple models within a single observer First, you need to generate your observer: command – rails g observer Auditor -observer classes are usually stored in app/models with the naming convention of app/models/audit_observer.rb.

In order to activate an observer, list it in the config.active_record.observers configuration setting in your config/application.rb file. config.active_record.observers = :comment_observer, :signup_observer Observers will not be invoked unless you define these in your application configuration.

Reference: http://apidock.com/rails/ActiveRecord/Observer

Difference between -%> and %> in rails

The extra dash makes ERB not output the newline after the closing tag. There’s no difference in your example, but if you have something like this:

<% if true -%>
<% end -%>
It’ll produce:
and not this:

Difference between render and redirect?

  1. Redirect is a method that is used to issue the error message in case the page is not found or it issues a 302 to the browser. Whereas, render is a method used to create the content.
  2. Redirect is used to tell the browser to issue a new request. Whereas, render only works in case the controller is being set up properly with the variables that needs to be rendered.
  3. Redirect is used when the user needs to redirect its response to some other page or URL. Whereas, render method renders a page and generate a code of 200.

Redirect is used as: redirect_to: controller => ‘users’, :action => ‘new’

Render is used as: render: partial render: new -> this will call the template named as new.rhtml without the need of redirecting it to the new action.

What is the use of rake commands?

  1. db:create——- creates the database for the current env
  2. db:create:all ———creates the databases for all envs
  3. db:drop ———-drops the database for the current env
  4. db:drop:all ———-drops the databases for all envs
  5. db:migrate ———-runs migrations for the current env that have not run yet
  6. db:migrate:up ——–runs one specific migration
  7. db:migrate:down ——-rolls back one specific migration
  8. db:migrate:status —–shows current migration status
  9. db:migrate:rollback —rolls back the last migration
  10. db:forward ————advances the current schema version to the next one
  11. db:seed (only) ———runs the db/seed.rb file
  12. db:schema:load ————loads the schema into the current env’s database
  13. db:schema:dump ———dumps the current env’s schema (and seems to create the db aswell)
  14. db:setup ————-runs db:schema:load, db:seed
  15. db:reset ———-runs db:drop db:setup
  16. db:migrate:redo ———runs (db:migrate:down db:migrate:up) or (db:migrate:rollback db:migrate:migrate) depending on the specified migration
  17. db:migrate:reset ——runs db:drop db:create db:migrate

What is eagerloading?

One way to improve performance is to reduce the number of database queries through eager loading.

You can know where we need eager loading through “Bullet’ Gem

What is Active Record?

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

How many types of callbacks available in ROR?

  • (-) save
  • (-) valid
  • (1) before_validation
  • (2) before_validation_on_create
  • (-) validate
  • (-) validate_on_create
  • (3) after_validation
  • (4) after_validation_on_create
  • (5) before_save
  • (6) before_create
  • (-) create
  • (7) after_create
  • (8) after_save

What are the variable in ruby?

  1. Local Variables – foobar
  2. Instance Variables – @foobar
  3. Class Variables – @@foobar
  4. Global Variables – $foobar

Name Begins With Variable Scope

  • $ A global variable
  • @ An instance variable
  • [a-z] or _ A local variable
  • [A-Z] A constant
  • @@ A class variable

What is the use of Global Variable in Ruby?

Syntatically, a global variable is a variable whose name begins with $ Global variables in Ruby are accessible from anywhere in the Ruby program, regardless of where they are declared. $welcome = “Welcome to Ruby Essentials”

Difference between “and” and && in Ruby?

and is the same as && but with lower precedence.

What is the use of Destructive Method?

Distructive methods are used to change the object value permanently by itself using bang (!) operator. ‘sort’ returns a new array and leaves the original unchanged. ‘sort!’ returns the same array with the modification. The ‘!’ indicates it’s a destructive method. It will overwrite the current array with the new result and returns it.

What is the use of load and require in Ruby?

The require() method is quite similar to load(), but it’s meant for a different purpose. You use load() to execute code, and you use require() to import libraries.

How does nil and false differ?

nil cannot be a value, where as a false can be a value A method returns true or false in case of a predicate, other wise nil is returned. false is a boolean data type, where as nil is not. nil is an object for NilClass, where as false is an object of for FalseClass

What is the difference between symbol and string?

Symbols have two nice properties compared to strings which can save you memory and CPU time The difference remains in the object_id, memory and process time for both of them when used together at one time Strings are considered as mutable objects. Whereas, symbols, belongs to the category of immutable Strings objects are mutable so that it takes only the assignments to change the object information. Whereas, information of, immutable objects gets overwritten

How to use super key word?

Ruby uses the super keyword to call the superclass implementation of the current method. Within the body of a method, calls to super acts just like a call to that original method. The search for a method body starts in the superclass of the object that was found to contain the original method.

def url=(addr)
 super (addr.blank? || addr.starts_with?(‘http’)) ? addr : http://#{addr}

Difference between puts and print?

puts adds a newline to the end of the output. print does not.

What is rake?

Rake is command line utility of rails. “Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility ‘make’, and uses a ‘Rakefile’ and .rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.” Putting in simple word : “rake will execute different tasks(basically a set of ruby code) specified in any file with .rake extension from comandline.”