Section 1

Preview this deck

Rails Console

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

4 years ago

Date created

Mar 14, 2020

Cards (34)

Section 1

(34 cards)

Rails Console

Front

Rails Console The Rails console allows you interact with a Rails application through the IRB command line, it starts IRB and loads the Rails environment. To use it, from the root of a Rails application directory.

Back

CRUD

Front

Create, Read, Update, Delete

Back

Rails Validations

Front

Validations are a type of ActiveRecord callback that can be used to ensure only valid data is stored in your Rails databases. The create, save and update methods trigger validations, and will only allow a valid ActiveRecord object to be saved to the database. Validations are defined in your models. Ex. class Person < ActiveRecord::Base validates_presence_of :name validates_numericality_of :age, :only_integer => true validates_ confirmation_of :email validates_length_of :password, :in => 8..20 end

Back

Schema

Front

Structure or organization of the tables within the database. Usually contained in db section of the application's directory.

Back

ActiveRecords in Rails

Front

Active Records are commonly used in Ruby as a means of persisting data, of saving data persistently, so that it can be recalled for later use, even after you've closed the program that created the data and turned off your computer. The Active Record pattern is used to access data stored in relational databases — it allows you to perform CRUD operations without worrying about the specific underlying database technology (e.g., SQLite, MySQL, PostgreSQL, SQL Server, Oracle, etc).

Back

rails new #app_name

Front

Create a new Ruby on Rails application with the given name here. This will give you the basic structure to immediately get started. After this command has successfully run your application is in a folder with the same name you gave the application. You have to cd into that folder.

Back

TDD

Front

In test-driven development (TDD) the mantra has always been red: write a failing test and run it, green: make the test pass, and refactor: look at the code and see if you can make it any better.

Back

Model (ActiveRecord)

Front

Models represent knowledge. A model notifies its associated views and controllers when there has been a change in its state. This notification allows the views to produce updated output, and the controllers to change the available set of commands. In some cases an MVC implementation may instead be 'passive' and other components must poll the model for updates rather than being notified. It updates and manipulates data that it receives from the controller and sends the result to view.

Back

ERB Delimiters

Front

The Ruby code between the delimiters <% and %> is run but the result will not be inserted at this point in the HTML. Therefore these tags are most commonly used for control flow structures such as an if statement in the example, or loops.

Back

method visibility (private, public)

Front

public can be accessed by everyone; protected can be accessed by class, package, subclass, not world; default (none) can be accessed by class and package; private can be accessed by class

Back

web application

Front

A web application is accessed by users over a network uses a browser as the client and consists of collections of client and server-side scripts HTML pages and other resources that may be spread across multiple servers.

Back

Version Control

Front

The practice of tracking and providing control over the changes made to source code. Examples : Github and Bitbucket.

Back

Classes in Ruby

Front

Classes are defined using the keyword class followed by the name of the class. Think of a class as blueprint to object or instance within Ruby.

Back

DRY

Front

Every piece of information should have a single, unambiguous, authoritative representation within a system. Duplication of code fragments throughout an application can lead to logical contradictions and in general make the application more difficult to maintain.

Back

Rails generate scaffold (#name attribute: type)

Front

The scaffold command magically generates all the common things needed for a new resource for you! This includes controllers, models and views. It also creates the following basic actions: create a new resource, edit a resource, show a resource, and delete a resource. That's all the basics you need. Take this example: rails generate scaffold product name:string price:integer Now you can create new products, edit them, view them and delete them if you don't need them anymore. Nothing stops you from creating a full fledged web shop now ;-)

Back

rails s

Front

Rails server (start the server) You have to start the server in order for your application to respond to your requests. Starting the server might take some time. When it is done, you can access your application under localhost:3000 in the browser of your choice. In order to stop the server, go to the console where it is running and press Ctrl + C

Back

View (ActionView)

Front

A view is a (visual) representation of the model. A view's purpose is to display this information in a human readable format. An important distinction to make is that it is the controller, not the view, where information is collected. The view should just display that information. By default, view templates are written in a language called eRuby (Embedded Ruby) which is processed by the request cycle in Rails before being sent to the user.

Back

Specify Access

Front

Public - no access control, can be called by anyone. Protected - can be invoked only by objects of the defining class and it's subclasses. Private - can only be called in the context of the current object, without on object reference on the LHS, two objects of the same class cannot invoke each other's private methods. Thus, the receiver of a private method is always self.

Back

db:migrate

Front

When you add a new migration, for example by creating a new scaffold, the migration has to be applied to your database. The command is used to update your database.

Back

Rails directory structure

Front

Back

Controller - (ActionController)

Front

A controller is the link between a user and the system. A controller's purpose is to receive specific requests for the application. Routing decides which controller receives which requests. Often, there is more than one route to each controller, and different routes can be served by different actions. Each action's purpose is to collect information to provide it to a view. This subsystem is implemented in ActionController which is a data broker sitting between ActiveRecord (the database interface) and ActionView (the presentation engine).

Back

Embedded Ruby (erb)

Front

It runs the Ruby code and inserts the result to the HTML at that position. You can put any kind of Ruby code between <%= and %>, for instance, <%= 9 * 3 %> will translate to 27 in the page that the user is viewing. However, typically this tag is used to display some data from a model, such as the price of a product, as shown in the example here.

Back

is-a / has-a

Front

is-a is based on inheritance (Student is a Human) -- look for extends; has-a is the use of instance variables that reference other objects (Student has a Brain)

Back

Instance Variable

Front

An instance variable can only be directly accessed or modified within a method definition.

Back

Relational Databases Relational

Front

Databases are the most common way to persistently store data in web applications. A relational databases is used to store a collection of relations. This involves storing records in tables.

Back

Class Method

Front

belongs to the class rather than instances of a class; best used when writing utility methods (not to be changed, method doesn't use instance variable, operation not dependent on instance creation, etc.

Back

Polymorphism

Front

subclasses of a class can share traits w/ parent and have own traits; ex: Student extends Human

Back

Distributed Version Control with Git

Front

Git provides means for comparing the differences between the various versions of the project ( snapshots) and for merging them accordingly. Main development branch = "Master". New versions may be created along the master branch, or new branches can be created off of it. These branches can possibly be merged back into the Master branch.

Back

Method

Front

method (as opposed to a function) a piece of code called by name and associated w/ an object; functions are independent of objects

Back

resources

Front

A resource is the term used for a collection of similar objects, such as articles, people or animal. You can create, read, update and destroy items for a resource and these operations are referred to as CRUD operations. For example: Rails.application.routes.draw do resources :articles root 'welcome#index' end

Back

Middleware

Front

Middleware is the software glue between the operating system and applications on each side of a client server architecture, some refer to it as the dash in client server. I like to think of middleware as the software that provides services to applications beyond those available from the underlying operating system — it connects applications running on the server side, and passes data between them. Thus, middleware allows multiple processes running on different machines to interact (where natively they would not be able to).

Back

Multiple Inheritance

Front

class can inherit from more than one parent class; Ruby is single inheritance

Back

Run Ruby Files

Front

$ Ruby (#app_name).rb it's executes the file and runs the code.

Back

Associations in Rails

Front

Associations in Rails When you have more than one model in your rails application, you would need to create connection between those models. You can do this via associations. Active Record supports three types of associations: one-to-one : A one-to-one relationship exists when one item has exactly one of another item. For example, a person has exactly one birthday or a dog has exactly one owner. one-to-many : A one-to-many relationship exists when a single object can be a member of many other objects. For instance, one subject can have many books. many-to-many : A many-to-many relationship 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. You indicate these associations by adding declarations to your models: has_one, has_many, belongs_to, and has_and_belongs_to_many.

Back