Interview Prep Flashcards
What standard seven restful actions for
resources :photos
Describe a class, an object, a module, and why we need them?
Classes are constructs that create instances of themselves and enables instances to have state and behavior. Objects are instances of class. Modules are a collection of methods and constants.
What are the three levels of method access control for classes?
The three levels of access are Public, Protected, and Private.
Public methods can be called by all object and subclasses and are enforced by no access control. Protected methods are only accessible to objects within the same class. Private methods are only accessible within the same instance.
What does self mean?
Self always refers to the current object. However, classes are also objects in Ruby. A candidate that notes that should get bonus points.
Describe functional testing.
In Rails, functional testing lets you test the response of various actions contained in a controller. The programmer should understand that the functional test will tell their testing library to expect certain responses based on control requests.
Always have the programmer program.
Knowing textbook answers for questions is one thing. Being able to execute Ruby-On-Rails is another. You always want to set up real world tests for your candidates. For a beginner position, have the candidate perform actions such as creating and setting up a Rails environment or using migration to manage a database.
Intermediate candidates should be able to perform actions such as setting up and deploying a Rails app for production.
Experienced candidates should be able to analyze current applications for things such as performance, memory, and security issues. Additionally they should model databases and analyze queries.
There is an abundance of self-proclaimed Ruby-On-Rails experts out there. Sifting through the pros and amateurs will take time but will prove worthwhile in the end.
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 MixedCase and have no underscore; each word starts with a 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.
Explain what is “Yield” in Ruby on Rail?
A Ruby method that receives a code block invokes it by calling it with the “Yield”.
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.
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 have an object_id 4
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 Rail 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.
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.
Explain how Symbol is different from variables?
Symbol is different from variables in following aspects
- It is more like a string than variable
- In Ruby string is mutable but a Symbol is immutable
- Only one copy of the symbol requires to be created
- Symbols are often used as the corresponding to enums in Ruby
Explain what is Rails Active Record in Ruby on Rail?
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
how you can create a controller for subject?
Command Line:
- ruby generate controller subject
what is Rail Migration?
Rail 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.
List out what can Rail Migration do?
Rail Migration can do following things
- Create table
- Drop table
- Rename table
- Add column
- Rename column
- Change column
- Remove column and so on
what is the role of Rails Controller?
A controller can thus be thought of as a middle man between models and views. It makes the model data available to the view so it can display that data to the user, and it saves or updates data from the user to the model.
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.
Explain what is Mixin in Rails?
Mixin in Ruby offers an alternative to multiple inheritances, using mixin modules can be imported inside other class.
Explain how you define Instance Variable, Global Variable and Class Variable in Ruby?
- Ruby Instance variable begins with — @
- Ruby Class variables begin with — @@
- Ruby Global variables begin with — $
Mention what is the difference between the Observers and Callbacks in Ruby on Rail?
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
Explain what is rake in Rail?
Rake is used for normal administration tasks like migrating the database through scripts, loading a schema into the database, etc.
The log that has to be seen to report errors in Ruby rails?
Rails will report errors from Apache in the log/Apache.log and errors from the Ruby code in log/development.log.