Skip to content
 

Ruby on Rails Interview Questions Part 1

Ruby on Rails Interview Questions and Answers


1. What are the advantages of Ruby on Rails?

There are several advantages of making use of Ruby on Rails. Some of these include: Plug-ins and Gems, Convention over Configuration, DRY Principal, Rest Support, Pure OOP Concept, Scaffolding, Rexml Support, Rpc Support, Action Mailer, and Rack Support.

 

2. Which programming language is used for Ruby?

Ruby was created by Matz. It is a brain child of this Japanese programmer. Principally, it is a language oriented on the cross platform object. This will help you to know what the code will do to your application. The legacy code gives you the necessary power to perform organization and administration tasks. As an open source, it had to go through great periods of development, at its various stages.

 

3. Which are some of the names commonly associated with Ruby?

Modules, constants, methods, variables, and classes can all be referred to by several popular Ruby names. If you want to differentiate between various names for Ruby, you can denote that by the name’s first character. Some of these names are frequently used in the form of reserve words that are however not to be used to depict other purposes. The name may either be in the form of upper-case letters, lower-case letters, numbers, or even underscores. It is necessary to ensure that you specifically follow these names by their known name characters.

 

4. Name prime difference between String and Symbol?

Symbols are the same as Strings, though the behavior of both can be differentiated based upon their respective ID, Process or CPU Time, and Memory. While Symbols are immutable, Stings on the other hand are mutable.

Though mutable objects allow change even after assignment, immutable objects may be overwritten only. For instance:

  • p :symbol_object_jak.object_id #=> 247378
  • p “string object jak”.object_id #=> 22956030
  • p “string object jak”.object_id #=> 22956070
  • p “string object jak”.object_id #=> 22956090
  • p ” string object jak “.to_sym.object_id #=> 247518
  • p :symbol_object_jak.to_s.object_id #=> 22687010
  • p :symbol_object_jak.to_s.object_id #=> 21141310
  • p :symbol_object_jak.to_s.object_id #=> 22704460

Further, there will also be a difference in Process Time. For instance, when Testing the values for any two Symbols, in order to establish their equality or non-equality, it is far quicker than Testing equality values for two Strings. It must however be noted that every unique String value carries an associated symbol with itself.

 

5. What is meant by Session as well as Cookies?

A Session is used for storing user information on side of the server, while a Cookie is used for storing information side of the browser, or what we may call the side of the client.

Session: Let’s say session[:user] = “amitkumar” will remain, even while the browser stays in a ‘not closed’ position.

 

6. What is the request.xhr?

The request.xhr helps to inform the controller when a fresh Ajax request is received. It will always return you ‘Boolean Values’, which is ‘True’ or ‘False’ statuses.

 

7. What is meant by MVC? And how does MVC work?

MVC tends for the Model-View Controller and is used by several languages, such as Python, Pearl, PHP, and others. Its flow is: The request comes first to your controller, which then looks for the most appropriate view for interaction with the model. The model then interacts with the database and in turn sends a response to the controller. Based on this response, the controller passes on the output parameter to the view. For instance, your URL is as follows: “http://localhost:2000/users/new”.

In this case, your controller is ‘users’ and the method used is ‘new’. In your ‘users/views’ folder, you must have a file that is entitled ‘new.html.erb’. Hence, when you press the ‘Submit’ button, the user model, or for that matter whatever you have chosen in the syntax rhtml form, will be automatically called upon and the values stored accordingly in your database, as may be defined.

 

8. What are the things that can be defined by us in the Model?

Several of the many things that can be defined by us in the Model include:

  • ROR Queries in the SQL
  • Relationship of Active Record Associations
  • If you install any plug-ins, such as Validation group, you can define such Validation group settings within your Model
  • Callbacks, such as before_create, after_save, before_save, etc.
  • Relationships, such as HABTM, or has_one, as well as has_many, etc.
  • Validations, such as format of, numericality of, validate presence of, etc.

 

9. What is meant by ORM in Ruby on Rails?

ORM tends to the Object-Relationship-Model. This means your Classes will be mapped to the table in your database, in addition to the Objects being directly mapped to rows in your table.

 

10. How many Associations Relationships Types do Models have?

If your rails application has more than a single Model, you will have to create a connection between your two Models. This can be achieved through Associations. Active Record will support the following three Associations types:

1). One-to-one: One-to-one type of relationship will exist when any one item possesses exactly one whole of another item type. For instance, a person will have exactly a single birthday or likewise a dog will also have exactly a single owner for all practical purposes.

2). One-to-Many: One-to-many type of relationship will exist when one object is a member of several other objects at once. For instance, one subject will have several books at one time.

3). Many-to-many: Many-to-many type of relationship will exist when one of the first objects relates to either one or even more than one of the second object, whereas this second object in turn is again related to either one or several first object at one time.

You can indicate such associations through the addition of declarations to your own Models, such as: has_one, has_many, belongs_to, and has_and_belongs_to_many.

 

11. Define helpers and their use in ROR?

Helpers are modules which provide you methods that can be automatically used in your view. Further, helpers provide shortcuts commonly used to display code. They also offer a way for keeping programming off your views.


ror interview questions and answeers fr experienced ror interview questions answers for 1 year experience

Leave a Reply