Ruby On Rails Interview Questions For Beginners

Interview-question

List of Ruby On Rails interview questions.

1) Explain what is Rails Active Record in Ruby on Rails?

Rails active record is the Object/Relational Mapping (ORM) layer supplied with Rails. It follows the standard ORM model as
Table map to classes
Rows map to objects
Columns map to object attributes


2) Explain how Rails implements Ajax?

Ajax powered web page retrieves the web page from the server which is new or changed, unlike another web-page where you have to refresh the page to get the latest information.
Rails trigger an Ajax Operation in the following ways.

Some trigger fires: The trigger could be a user clicking on a link or button, the users inducing changes to the data in the field or on a form

Web client calls the server: A Java-script method, XMLHttpRequest, sends data linked with the trigger to an action handler on the server. The data might be the ID of a checkbox, the whole form or the text in the entry field

The server does process: The server-side action handler does something with the data and retrieves an HTML fragment to the web client

The client receives the response: The client-side JavaScript, which Rails generate automatically, receives the HTML fragment and uses it to update a particular part of the current


3) Mention how you can create a controller for the subject?

To create a controller for subject you can use the following command
C:\ruby\library> ruby script/generate controller subject

4) Mention what is Rails Migration?

Rails Migration enables Ruby to make changes to the database schema, making it possible to use a version control system to leave things synchronized with the actual code.

5) List out what can Rails Migration do?

Rails Migration can do the following things
Create table
Drop table
Rename table
Add column
Rename column
Change column
Remove column and so on


6) Mention what is the command to create a migration?

To create migration command includes
C:\ruby\application>ruby script/generate migration table_name

7) Explain when self.up and self.down method is used?

When migrating to a new version, self.up method is used while self.down method is used to roll back my changes if needed.

8) Mention what is the role of Rails Controller?

The Rails controller is the logical center of the application. It facilitates the interaction between the users, views, and the model. It also performs other activities like
It is capable of routing external requests to internal actions. It handles URL extremely well
It regulates helper modules, which extend the capabilities of the view templates without bulking of their code
It regulates sessions; that gives users the impression of ongoing interaction with our applications


9) Mention what is the difference between Active support’s “HashWithIndifferent” and Ruby’s “Hash”?

The Hash class in Ruby’s core library returns value by using a standard “= =” comparison on the keys. It means that the value stored for a symbol key cannot be retrieved using the equivalent string. While the HashWithIndifferentAccess treats Symbol keys and String keys as equivalent.

10) Explain what is Cross-Site Request Forgery (CSRF) and how Rails is protected against it?

CSRF is a form of attack where hacker submits a page request on your behalf to a different website, causing damage or revealing your sensitive data. To protect from CSRF attacks, you have to add “protect_from_forgery” to your ApplicationController. This will cause Rails to require a CSRF token to process the request. CSRF token is given as a hidden field in every form created using Rails form builders.

For next 10 Rails Interview questions and Answes Click hear for Part 3

Leave a Reply

Your email address will not be published. Required fields are marked *