Interview Questions.

Ruby on Rails Interview Questions and Answers

fluid

Ruby on Rails Interview Questions and Answers

Q1. In which Programming language became Ruby written?

Ans: Ruby become written in C language and Ruby on Rails written in Ruby.

Q2. Mention all of the naming conventions in ruby on rails.

Ans: Following is a list of some naming conventions used in ruby on rails: –

Variables– it is used for the assertion of variables wherein all the letters ought to be in lowercase and the phrases ought to be separated by way of underscore.

Class and module– a category is declared which encapsulates each function. The magnificence or module call can be written in mixed case and no underscores are used. Every word have to begin with an uppercase letter.

Database table– a table is made for storing the statistics. It is similar to the naming conventions for variables.

Model– mixed case is used and feature singular with table name.

Controller– names are represented in plural form.

Q3. What is ORM in Rails?

Ans: ORM has a tendency for Object-Relationship-Model, it manner that your Classes are mapped to desk in the database, and Objects are directly mapped to the rows inside the table.

Q4. Why Ruby on Rails?

Ans: There are plenty of gain of using Ruby on Rails.

DRY Principal( Don’t Repeat Yourself): It is a principle of software development aimed at decreasing repetition of code. “Every piece of code ought to have a single, unambiguous illustration inside a gadget”

Convention over Configuration: Most web improvement framework for .NET or Java pressure you to write pages of configuration code. If you comply with suggested naming conventions, Rails doesn’t want a lot configuration.

Gems and Plugins:RubyGems is a package deal manager for the Ruby programming language that gives a fashionable layout for dispensing ruby packages and library.

Plugins: A Rails plugin is either an extension or a change of the middle framework. It gives a way for builders to percentage bleeding-part thoughts without hurting the solid code base. We need to decide if our plugin will be potentially shared across distinctive Rails programs.

Scaffolding: Scaffolding is a meta-programming technique of constructing database-backend software utility. It is a technique supported through MVC frameworks, wherein programmer may write a specification, that describes how the software database can be used. There are two kind of scaffolding:

static: Static scaffolding takes 2 parameter i.E your controller name and model name.

Dynamic: In dynamic scaffolding you need to outline controller and version one by one.

Rack Support: Rake is a software venture management device. It permits you to specify obligations and describe dependencies as well as to institution obligations in a namespace.

Metaprogramming: Metaprogramming techniques use applications to put in writing programs.

Bundler: Bundler is a new idea brought in Rails 3, which lets you manage your gemstones for utility. After specifying gem record, you need to do a package deal deploy.

Rest Support.

Action Mailer

Q5. Explain the functions of ruby on rails.

Ans: Some of the functions of ruby on rails are indexed beneath-

Meta-programming: code generation is used however for heavy lifting, it makes use of meta-programming.

Active record: objects are saved to the database thru this framework. It identifies the columns in a schema and binds them in your domain object.

Scaffolding: it means it has the capability of creating temporary code mechanically.

Convention over configuration: tons configuration is not needed if the naming conference is observed.

Three environments: testing, improvement, and production are the 3 default environments on this framework.

Built-in testing: take a look at instances are used in this for writing and executing the codes.

Q6. How many Types of Associations Relationships does a Model has?

Ans: When you have got a couple of version in your rails utility, you would want to create connection among those fashions. You can try this via associations. Active Record helps three kinds of institutions:

one-to-one : A one-to-one dating exists while one item has exactly one in all every other item. For example, a person has exactly one birthday or a dog has exactly one proprietor.

One-to-many : A one-to-many relationship exists when a unmarried item can be a member of many different items. For example, one difficulty could have many books.

Many-to-many : A many-to-many courting exists whilst the primary object is associated with one or extra of a second object, and the second object is related to one or among the first item.

You imply these associations via including declarations for your models: has_one, has_many, belongs_to, and has_and_belongs_to_many.

Q7. What is MVC? And How it Works?

Ans: MVC essentially shows Model-View-Controller. And MVC used by many languages like PHP, Perl, Python and many others. Generally MVC works like this:

Request first involves the controller, controller reveals and suitable view and interacts with version, model interacts together with your database and ship the response to controller then controller based totally on the reaction give the output parameter to view.

Q8. What do you understand by way of rails?

Ans: It is an internet software framework that's written in ruby language and is developed by using David Hansson. It is an open supply ruby framework for the development of database backend net utility. It consists of the whole lot which is wanted for creating a database pushed net application with the help of model view controller pattern.

Q9. What is the Difference among Static and Dynamic Scaffolding?

Ans: 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 separately.

Q10. How many types of relationships does a Model has?

Ans:

has_one

belongs_to

has_many

has_many :through

Q11. What are the extraordinary filters used in ruby on rails?

Ans: The strategies that are used before and after the action of the controller technique are accomplished. It guarantees that the code runs with the given action approach which is called. Three styles of filters are supported by way of rails. They are: –

Before filters: those filters are performed earlier than the execution of the code in the movement controller.

After filters: those filters are done after the execution of the code within the motion controller.

Around filters: these are done both earlier than and after the execution of the code present in the movement controller.

Q12. How you run your Rails Application with out developing database ?

Ans: MYou can run software with the aid of uncomment the road in surroundings.Rb

Path => rootpath conf/ environment.Rb

# Skip frameworks you're no longer going to use (handiest works if the use of vendor/rails)

config.Frameworks -= [ :action_web_service, :action_mailer,:active_record ].

Q13. What is Ruby Gems?

Ans: Ruby Gem is a software program package deal, usually referred to as a "gem". Gem includes a packaged Ruby utility or library. The Ruby Gems software itself permits you to effortlessly down load, install and manipulate gems on your system.

Q14. Explain the role of sub listing app/controllers and app/helpers.

Ans:

App/controllers: in this, a web request is made with the aid of the consumer which is treated through the controller. Rails make use of this controller sub directory for finding the controller elegance.

App/helpers: some helper training are gift within the helper sub listing that's used for helping the view, version and the controller training found in it.

Q15. What are helpers and the way to use helpers in ROR?

Ans: Helpers ("view helpers") are modules that provide techniques which might be routinely usable in your view. They provide shortcuts to usually used show code and a way to be able to maintain the programming out of your perspectives. The motive of a helper is to simplify the view. It's high-quality if the view file (RHTML/RXML) is brief and candy, so that you can see the structure of the output.

Q16. What is the simple distinction among GET and POST technique?

Ans: GET is largely for simply getting (retrieving) the information, while POST may also used to do a couple of matters, like storing or updating records, or ordering a product, or sending E-mail and so on.

Q17. What do you recognize via rails migration and what it could do?

Ans: With the help of rails migration, we can make modifications in the database schema which makes it feasible to apply the version control gadget for synchronization of these matters with the real code. Rails migration can carry out the subsequent things: –

It allows in developing the desk for the database.

Dropping the table is possible with the assist of this.

Renaming of the table is viable.

We may even add columns.

Renaming of the columns can be achieved.

Columns can be changed too.

We can cast off the columns and various other things may be completed.

Q18. Mention the function of rails controller.

Ans: The rails controller works as the primary logical centre of the utility. With the assist of this consumer, perspectives,and fashions can engage with every other. Routing of external requests to internal moves is viable. It can handle the URL thoroughly. It allows in regulating helper modules which extends the abilities of view templates. It also regulates the session which gives consumer an influence of an on-going interplay with any application.

Q19. How do the following methods range: @my_string.Strip and @my_string.Strip! ?

Ans: The strip! Approach modifies the variable at once. Calling strip (without the !) returns a duplicate of the variable with the adjustments, the unique variable isn't always altered.

Q20. What is Bundler?

Ans: Bundler is a new idea introduced in Rails3, which enables to you manage your gems for the application. After specifying gems on your Gemfile, you want to do a package deal set up. If the gem is to be had in the machine, bundle will use that else it's going to choose up from the rubygems.Org.

Q21. Mention the variations between the observers and callbacks in ruby on rails.

Ans: Following are the variations among observers and callbacks in ruby on rails: –

Rails observers: these are equal as callbacks however are used while the method is not without delay associated to the existence cycle of the object. It lives for a longer duration of time and can be attached or indifferent at any time.

Rails callback: the callback strategies can simplest be called at only positive factors of time inside the lifestyles cycle of an item like validation, advent, updating, deletion, and so forth. Unlike the rails observers, the rails callback lives for handiest a short time frame.

Q22. What's the distinction in scope for those  variables: @name and @@name?

Ans: @call is an example variable and @@name is a class variable.

Q23. Does Ruby guide constructors? How are they declared?

Constructors are supported in Ruby. They are declared as the method initialize, proven under. The initialize method receives called robotically whilst Class.New is known as. 

 

Q24. What is the log that has to see to check for an errors in ruby rails?

Rails will record mistakes from Apache in log/apache.Log and mistakes from the Ruby code in log/development.Log. If you are having a problem, do have a observe what these logs are announcing. On Unix and Mac OS X you could run tail -f log/improvement.Log in a separate terminal to reveal your application's execution.
 

Q25. What is the usage of global variable $ in Ruby?

Ans: A magnificence variable starts offevolved with an @@ signal that's right away accompanied by way of upper or lower case letter. You also can put a few call characters after the letters which stand to be a pure non-compulsory. A magnificence variable may be shared among all of the items of a class. A single replica of a category variable exists for every and every given elegance. To write a worldwide variable you start the variable with a $ signal which have to be observed with the aid of a name man or woman. Ruby defines a number of global variables which also include different punctuation characters along with $_ and $-okay.

Q26. Where does the start_tabnav gets informations for tabs rendering in ruby rail?

Ans: The most important Symbol permit the start_tabnav method known to look for a special MainTabnav magnificence wherein all are occurs.




CFG