Rails Basics Flashcards

1
Q

What is Rails

A

open source web application framework written in Ruby.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Active Record Pattern

A

a database table is represented as a class; each row of the tables is created/updated by an object instance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Convention over Configuration

A

A software design that decreases the number of decisions to be made by developers
E.g. Rails automatically render views with names that correspond to valid routes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Framework?

A

A framework is a program or code library that writes most of your application for the developer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is MVC?

A

Model: Application data.

View: Presentation layer

Controller: Processes and responds to events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does MVC work?

A

Request first comes to the controller, controller finds the appropriate view and interacts with model, model interacts with your database and send the response to controller then controller based on the response give the output parameter to view

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain RESTful Architecture

A

REST = REpresentational State Transfer

It uses HTTP methods GET, PUT, POST, or DELETE

RESTful interface means clean URLs, less code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why Rails?

A

DRY Principal( Don’t Repeat Yourself)

Convention over Configuration

Gems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the ORM of rails?

A

ORM stands for Object-Relationship-Model, where classes are mapped to tables in the database, and objects are directly mapped to the rows in the table

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What Associations Relationships does a Model have?

A

one-to-one: exists when one item has exactly one of another item.

one-to-many: exists when a single object can be a member of many other objects.

many-to-many: exists when the first object is related to one or more of a second object, and the second object is related to one or many of the first object.

belongs_to
has_one
has_many
has_many :through
has_one :through
has_and_belongs_to_many
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the Ruby naming convention for methods?

A

Lowercase names that may be followed by digits, underscores, letters, e.g. paint or close_the_door

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Instance and Class variables?

A

Instance variables(@): the data varies with each instance of the object. @i = 1

Class variables(@@): “static variables”, shared across all instances of a class.  
@@i = 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between empty , nil and blank?

A

Nil: used on any object and is true if the object is nil

Empty: can be used on strings, arrays and hashes and returns true if:
String length == 0;
Array length == 0;
Hash length == 0;

.blank? evaluates true on strings which are non-empty but contain only whitespace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a destructive method?

A

It is a method that alters the attribute of an object.
Example:
myabcs = [‘a’, ‘b’, ‘c’] #myabcs is of type Array
myabcs.reverse! #this method altered the object
p myabcs #outputs
#[[“c”,”b”,”a”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are the variable scopes?

A

Local variables are local to the code construct in which they are declared. eg: method, loop.
must begin with either an underscore or a lower case letter
i = 5

Global variables accessible from anywhere in the Ruby program.
$speed = 10

Class variable is shared amongst all instances of a class. Only one variable value exists for all objects. If one object instance changes the value of the variable, that new value will change for all other object instances.
@@i = 5

Instance variables are local to specific instances of an object.
@i = 5

Ruby constants are values which, once assigned a value, should not be changed.
GRAVITATIONAL_CONST = 6.67

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Name a few object oriented concepts in Ruby.

A

Classes, Objects, Inheritance, Singleton methods, polymorphism(accomplished by overriding and overloading) are some object oriented concepts supported by Ruby

17
Q

Provide an example if how an iterator is used?

A
times
Iterate through the block 3 times, n starts at 0 and ends at 2 and is incremented by 1 each time. n is the block variable. 
3.times do |n|
puts n
end
upto
Iterate through the block 3 times, starting at 1 and ending at 3, each time incrementing by 1. n is the block variable.
1.upto(3) do |n|
puts n
en
downto
Iterate through the block 3 times, starting at 3 and ending at 1, each time decrementing by 1. n is the block variable.
3.downto(1) do |n|
puts n
end
18
Q

When to use Load vs Require in Ruby?

A

Require loads the file only once, while load loads it every time it is called
Use load rather than require if you need to force something to reload (e.g. a web server or a test server)
Load takes in a file’s full name path such as:
load “/path/to/file.rb”

19
Q

Argument vs Parameter

A
The parameter is what is declared/ defined in a method or a class
An argument is the value that is passed when calling the function or instantiating the class. Example: 
class Person
    attr_accessor :name, :age
    def initialize(name = '', age = 0)
        self.name = name
        self.age = age
20
Q

RESTfull Resources

A
GET	/photos	photos#index	
GET	/photos/new	photos#new
POST	/photos	photos#create
GET	/photos/:id	photos#show
GET	/photos/:id/edit	photos#edit
PATCH/PUT	/photos/:id
DELETE	/photos/:id