Friday 6 February 2015

50 TOP Ruby on Rails Interview Questions and Answers for freshers and experienced pdf

Below are some important Ruby on Rails interview questions which are asked in most MNC company interviews for beginners or professionals.

1. Why Ruby on Rails? | Ruby On Rails Questions
There are lot of advantages of using ruby on rails
1. DRY Principal
2. Convention over Configuration
3. Gems and Plugins
4. Scaffolding
5. Pure OOP Concept
6. Rest Support
7. Rack support
8. Action Mailer
9. Rpc support
10. Rexml Support
11. etc..

2. Explain about the programming language ruby? | Ruby On Rails Questions
Ruby is the brain child of a Japanese programmer Matz. He created Ruby. It is a cross platform object oriented language. It helps you in knowing what your code does in your application. With legacy code it gives you the power of administration and organization tasks. Being open source, it did go into great lengths of development.

3. Explain about ruby names? | Ruby On Rails Questions
Classes, variables, methods, constants and modules can be referred by ruby names. When you want to distinguish between various names you can specify that by the first character of the name. Some of the names are used as reserve words which should not be used for any other purpose. A name can be lowercase letter, upper case letter, number, or an underscore, make sure that you follow the name by name characters.

4. What is the Difference between Symbol and String? | Ruby On Rails Questions
Symbol are same like string but both behaviors is different based on object_id, memory and process time (cpu time) Strings are mutable , Symbols are immutable.
Mutable objects can be changed after assignment while immutable objects can only be overwritten. For example
p "string object jak".object_id #=> 22956070
p "string object jak".object_id #=> 22956030
p "string object jak".object_id #=> 22956090

p :symbol_object_jak.object_id #=> 247378
p :symbol_object_jak.object_id #=> 247378
p :symbol_object_jak.object_id #=> 247378

p " string object jak ".to_sym.object_id #=> 247518
p " string object jak ".to_sym.object_id #=> 247518
p " string object jak ".to_sym.object_id #=> 247518

p :symbol_object_jak.to_s.object_id #=> 22704460
p :symbol_object_jak.to_s.object_id #=> 22687010
p :symbol_object_jak.to_s.object_id #=> 21141310

And also it will differ by process time
For example:
Testing two symbol values for equality (or non-equality) is faster than testing two string values for equality,
Note : Each unique string value has an associated symbol

5. What is Session and Cookies? | Ruby On Rails Questions
Session: are used to store user information on the server side.
cookies: are used to store information on the browser side or we can say client side
Session : say session[:user] = “arunkumar” it remains when the browser is not closed

6. What is request.xhr? | Ruby On Rails Questions
A request.xhr tells the controller that the new Ajax request has come, It always return Boolean values (TRUE or FALSE)

7. What is MVC? and how it Works? | Ruby On Rails Questions
MVC tends for Model-View-Controller, used by many languages like PHP, Perl, Python etc. The flow goes like this: Request first comes to the controller, controller finds and appropriate view and interacts with model, model interacts with your database and send the response to controller then controller based on the response give the output parameter to view, 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.

8. What things we can define in the model? | Ruby On Rails Questions
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
6. Active record Associations Relationship

9. What is ORM in Rails? | Ruby On Rails Questions
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.

10. How many Types of Associations Relationships does a Model has? | Ruby On Rails Questions
When you have more than one model in your rails application, you would need to create connection between those models. You can do this via associations. Active Record supports three types of associations:
one-to-one : A one-to-one relationship exists when one item has exactly one of another item. For example, a person has exactly one birthday or a dog has exactly one owner.
one-to-many : A one-to-many relationship exists when a single object can be a member of many other objects. For instance, one subject can have many books.
many-to-many : A many-to-many relationship exists when the first object is related to one or more of a second object, and the second object is related to one or many of the first object.
You indicate these associations by adding declarations to your models: has_one, has_many, belongs_to, and has_and_belongs_to_many.
More Questions & Answers :-

1 comment:

  1. Ruby Interview Questions and Answers
    http://allinterviewquestionsandanswerspdf.blogspot.in/2016/06/top-26-ruby-interview-questions-and.html

    ReplyDelete