Ruby on Rails Course Overview
Ruby on Rails
Ruby on Rails Training Course
Ruby on Rails Interview Questions & Answers
1) What is Ruby on Rails & why it is used for?
Ruby on Rails is an open-source web development tool that is built on top of Ruby programming language. Designed around productivity and simplicity, this framework gives developers a structure for writing code for building websites and web applications.
2) Who Developed Ruby on Rails?
David Heinemeier Hansson
3) Explain the Advantages of Ruby on Rails?
- Integrated application
- Default configuration saves a lot of time and work.
- Great ecosystem helps you find online tools & support.
- Active development status keeps introducing fixes & adding features.
- Testing frameworks are strong.
4) What is the latest version of ruby on rails?
5) Explain what is class libraries in Ruby?
Class libraries in Ruby consist of a variety of domains, such as data types, thread programming, various domains, etc.
6) Mention what is the naming convention in Rails?
- Variables: For declaring Variables, all letters are lowercase, and words are separated by underscores
- Class and Module: Modules and Classes uses Mixed Case and have no underscore; each word starts with an uppercase letter
- Database Table: The database table name should have lowercase letters and underscore between words, and all table names should be in the plural form for example invoice_items
- Model: It is represented by unbroken MixedCase and always have singular with the table name
- Controller: Controller class names are represented in plural form, such that OrdersController would be the controller for the order table.
7) Explain what is “Yield” in Ruby on Rails?
A Ruby method that receives a code block invokes it by calling it with the “Yield”.
8) Explain what is ORM (Object-Relationship-Model) in Rails?
ORM or Object Relationship Model in Rails indicate that your classes are mapped to the table in the database, and objects are directly mapped to the rows in the table.
9) Mention what the difference is between false and nil in Ruby?
In Ruby False indicates a Boolean datatype, while Nil is not a data type, it has an object_id 4.
10) Mention what are the positive aspects of Rails?
Rails provides many features like:
- Meta-programming: Rails uses code generation but for heavy lifting it relies on meta-programming. Ruby is considered as one of the best language for Meta-programming.
- Active Record: It saves object to the database through Active Record Framework. The Rails version of Active Record identifies the column in a schema and automatically binds them to your domain objects using metaprogramming
- Scaffolding: Rails have an ability to create scaffolding or temporary code automatically
- Convention over configuration: Unlike other development framework, Rails does not require much configuration, if you follow the naming convention carefully
- Three environments: Rails comes with three default environment testing, development, and production.
- Built-in-testing: It supports code called harness and fixtures that make test cases to write and execute.
11) Explain what is the role of sub-directory app/controllers and app/helpers?
- App/controllers: A web request from the user is handled by the Controller. The controller sub-directory is where Rails looks to find controller classes
- App/helpers: The helper’s sub-directory holds any helper classes used to assist the view, model and controller classes.
12) Mention what is the difference between String and Symbol?
They both act in the same way only they differ in their behaviors which are opposite to each other. The difference lies in the object_id, memory and process tune when they are used together. Symbol belongs to the category of immutable objects whereas Strings are considered as mutable objects.
13) What is Rails active record?
It is the ORM layer that is supplied with Rails and it follows the ORM model as follows:
- Map Table to classes
- Map Rows to objects
- Map Columns to object attributes
14) How do Rails implement Ajax?
Ajax-powered pages retrieve the page from the server. This page is unlike other web pages where you have to refresh the page to see the latest update. Rails trigger Ajax in the following ways:
- When a user clicks a button, he or she induces changes in the form or field.
- A Java-script method sends trigger-linked data to a handler on the server.
- The server-side handler works on the data and retrieves an HTML to the web client.
15) Mention how you can create a controller for subject?
To create a controller for subject you can use the following command:
C:\ruby\library> ruby script/generate controller subject
16) 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.
17) List out what can Rails Migration do?
Rails Migration can do following things:
- Create table
- Drop table
- Rename table
- Add column
- Rename column
- Change column
- Remove column and so on
18) What is Rails Migration? What can it do?
Rails Migration enables to make changes to the database, allowing it to use a version control system for synchronizing things with actual code. It can perform the following functions:
- Create, drop, rename table
- Add, rename, change and remove a column
19) When are self.up and self.down methods used?
self.up is used for migrating to a new version, while self.down is used to roll back changes.
20) What is Cross-Site Request Forgery (CSRF)? How is Rails protected against it?
It is a form of attack where a hacker submits a request on your behalf to a website, causing damage or revealing sensitive data. In order to protect from attacks, you must add “protect_from_forgery” to your ApplicationController. This will require a CSRF token to process the request.
21) How can you run Rails without creating databases?
You can run your application by uncommenting in environment.rb
path=> rootpath conf/environment.rb
config.frameworks = [ action_web_service, :action_mailer, :active_record]
22) How are Observers and Callbacks different from each other?
Observers are the same as Callback, but they are used when the method is not directly associated with the object. The observer lives longer, and can be detached or attached at any time.
Callbacks are methods that can be called only at certain moments of an object’s lifecycle. Callbacks live shorter.
23) What is Rake?
It is a Ruby Make or a utility that is used for administrative tasks such as migrating the database through scripts and loading schema into the database. In Rails, it substitutes the Unix utility ‘make’ and uses ‘Rakefile’ and ‘.rake files’ to build up task lists.
24) What do you mean by the term Scaffolding and what sort of advantages the Ruby can offer when it comes to same?
While developing the projects, the users often have to write codes in the early stage of development. These codes help building the application in a very reliable manner and quickly and also, a close eye can be kept on the working of some major components with this approach. In Ruby, the scaffolding is done automatically and the users are free to concentrate on the core development only from the first day of development.
25) What exactly are Harnesses and Fixtures in the Ruby?
These are basically the supporting codes with the help of which the users can easily write and can run the test cases. With the help of rake, the users can then simply proceed with the automated tests.
26) Name the three default environments in the Rails?
27) What role does garbage collection play?
- It enables removal of pointer values that are left behind after the program execution ends.
- It releases the programmer from tracking objects that get created dynamically on runtime.
- It facilitates the removal of distant objects from the memory so that other processes can use the memory.
28) How is direct different from render?
Redirect is used to issue the error message when the page is not found in the browser. This function tells the browser to issue a new request.
Render is used to make the content and it only works when the controller is being set up with the variables that require rendering.
29) What is the importance of RJs?
30) How is calling super() different from the super call?
A call to super() initiates the parent method without any disputes.
A call to super initiates the parent method with the same disputes that were passed to the child. An error will occur if the arguments passed to the child do not match with the parent method.
31) What are Float, Dig and Max?
Float is used when the function changes constantly.
Dig is used when you want to show a float in decimal digits.
Max is used when there is a need of Float.
32) What exactly are the pre-software requirements for developing a project with Ruby on Rails?
There should be a database system installed on the system and a web server to store and control all the activities and concerned programs. Also, the Rails framework and installation of Ruby should be done in a reliable manner. The users can go ahead with the WeBrick server which comes with this framework. Generally, there are other options as well that most of the users often go with and they are Apache and TPD.
33) While writing the Rails Application, what are the tasks which you need to pay attention to?
There are actually three important tasks that the users should be careful about and they are:
The very first thing is to describe as well as model the application domain. Next is to specify what can actually happen in the domain and what the critical factors to pay attention to are. The user must also pay a close attention to the views of the design available from those who have already considered the same
34) What exactly class libraries in ruby have in them?
They generally consist of domains like thread programming, data types, as well as other useful domains which are relevant in the development.
35) What is object relationship model in the Ruby on Rails?
The same indicates clearly that all the classes are mapped to the systems in the shortest possible time and the best part is the users are free to keep up the pace in the long run. It also represents that the classes are mapped to the rows and the tables.
36) What do you mean by the term Rail Migration?
It is basically an approach with the help of which the users can make the changes to the already existing database Schema in Ruby and can implement a version control system. The main aim is to synchronize the objects to get the quality outcomes.
37) How many types of variables are available in Ruby Class?
Mainly four types of variables are available in Ruby Class - local variables, global variables, class variables and instance variables.
38) How are the key differences between Python and Ruby?
- There are options for carrying out an action.
- It a reflective and object-oriented programming language.
- Used for functional programming.
- Frequent updates.
- There is one specific way to carry out an action.
- It is a high-level and general purpose language.
- Used for scientific programming.
- Fewer updates.
39) Explain what is Mixin in Rails?
Mixin in Ruby offers an alternative to multiple inheritances, using mixin modules can be imported inside other class.
40) Mention what is the difference between the Observers and Callbacks in Ruby on Rails?
- Rails Observers: Observers is same as Callback, but it is used when method is not directly associated to object lifecycle. Also, the observer lives longer, and it can be detached or attached at any time. For example, displaying values from a model in the UI and updating model from user input.
- Rails Callback: Callbacks are methods, which can be called at certain moments of an object’s life cycle for example it can be called when an object is validated, created, updated, deleted, A call back is short lived. For example, running a thread and giving a call-back that is called when thread terminates.