Ruby and Rails Work

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

app/controlelrs

contains controllers

app/helpers

contains programs with classes to help model, view, or controller classes

app/config/database.yml

database configuration file

how do you write an initialize method

def initialize(a, b, c) @a_variable = a @b_variable = b @c_variable = c

an intializing method example

def initialize(id) @cust_id = id end

get infinite arguments in a function

def something(*x)

how do you write a method

def test end

hashname.delete('key')

delete one has element

how do you imbed a module into a class

include Modulename

packets

information sent over the internet broken in smaller pieces

where do you define a local variable

inside a method

@variable is a/an

instance variable

what is a class

instructions to tell ruby to make a new type of thing

how do you define a global variable

$name

to print out a string as long as you like

%q {}

how to make a string that goes across multiple line with no quotes

%q{ }

and logic operator

&&

example of an each do loop

(0..5).each do |i| puts "Value of local variable is #{i}" end

how do you write a class variable

@@variablename

how do you write an instance variable

@variablename

how do you create an app in heroku

heroku create

what is a module

a way of groping together methods classes and constants

what does a controller handle

a web request from a user

how do you make an app in heroku

heroku create

app folder

holds application components like views, controllers and models

components

holds applications that bundle model, view, and controller

containers

A container image is a lightweight, stand-alone, executable package of a piece of software that includes everything needed to run it:

#merge two hashes

h1 ={ "a" => "A"} h2 = {"c" => "C"} h1.merge!(h2)

app/models

has classes that model the data stored in the application database

app/view

holds display templates to fill in with data from our applicaiton, convert to html, and return to the user's browser

how do you print out a hash table

hsh.each do | key , value| print key, "is", value, "\n" end

acts_as_commontable

ides a single Comment model that can be attached to any model(s) within your app.

see which parameterd you get from a controller method

render plain: params[:articles].inspect

what is the equivalent command of python's import in ruby

require

add resources to routes.rb

resources :articles

arrayname.pop

return the end of the array while shortening it by one

how to make a new line in a string

"\n"

class X: def initialize(J

"class X has-a initialize that takes a J parameter

range inclusive

..

range exclusive

...

what extension do ruby files have

.rb

turn string to a float

.to_f

how you enclose ruby code in an erb document

<% %>

How do you enclose code to be printed out in an erb document

<% = %>

link to another from within a view

<%= link_to 'link text' , path_to_find %>

how do you insert a link in html?

<a href = "url"> Something </a>

how do you italicize in html

<em> </em>

how do you insert an image in html?

<img src = "url">

how do you make something bold in html?

<strong> </strong>

long comment in Ruby

= begin = end

class variable naming

@@no_of_customers

what are the three components of rails

Action controller, action view, active record

main steps to Set up rails project with postgres

After making postgresql instance 1.) gem install pg 2.) rails new myapp --database=postgresql 3.)edit database.yml 4.) rake db:setup

the 4 components of the TCP/IP model

Application, Transport, Internetwork, Link

get the first commandline argument

Argv.first

what are the standard SQL commands

CREATE, SELECT, INSERT, UPDATE, DELETE, and DROP, GRANT, REVOKE

how to check if a file exists

File.exist?(nameoffileargument)

how to delete a file

File::delete("file")

#to open a file

File::open("filename", "mode") mode can be "w", "a", "r"

#how to read a file

File::read("file.txt")

how to rename a file

File::rename("oldname", "newname")

what does ERB let you do

It lets you put Ruby code inside of an HTML file

how to create an empty new file on the command line in windows

NUL > newfile

acts_as_paranoid

This gem can be used to hide records instead of deleting them, making them recoverable later

what is a Procfile

a text file that declares what command starts your app

escape key for strings

\

double quote

\"

single quote

\'

bell

\a

escape backspace

\b

formfeed

\f advance downward to the next page

Character with octal value ooo

\ooo

return key

\r

carriage return

\r go back to front of current line without moving down

escape tab

\t

Character with 16-bit hex value xxxx (Unicode only)

\uxxxx

ASCII vertical tab (VT)

\v

Character with hex value hh

\xhh

the most basic definition of the internet

a bunch of connected router that are moving packets

what is bundled software

a bunch of software all together

what is a container

a class, data structure, or an abstract data type whose instances are collections of other objects

daemon

a computer program that runs in the background

what is a procfike

a file that declares the commands to start your ap

IP address

a number assigned to a computer such that message can be routed to it

what is a record

a row in a table

Proxy server

a server that sits between two servers and sort of relays messages for them

hop

a single physical network connection

Thread

a small sequence of programmed instructions

what three main things does a packet contain (in addition to its content)

a source address, a destination address, information about how it can be put back together

what is a staging server

a special server used for testing

what is a database object

a table

Docker

a techno company that offers containers

what is double :: used for

accessing constants

where can you use global variables

across different classes

how to add a comment to a model instance

add this to a model : class Post < ActiveRecord::Base acts_as_commentable end and this to the model's controller commentable = Post.create comment = commentable.comments.create comment.title = "First comment." comment.comment = "This is the first comment." comment.save and fetch them from the view: commentable = Post.find(1) comments = commentable.comments.recent.limit(10).all

what is scaling

adding more resources for a particular application

what is scaling?

adding more resources for a particular application

how to open up a new file for appending

afile = file.new("filename", "rt")

how to write a file called afile

afile.syswrite

what does a class variable belong to?

alll objects of the class

how to change windows with just keys

alt + tab

if you return multiple items what are you actually returning?

an array

to assign things to your object what do you need within your class

an initialization method

how to loop through an array and print each item

arrayname.each do |i| puts i end

how do you reverse an array

arrayname.reverse

how do you sort an array

arrayname.sort

How do you make a new array

ary = Array.new

to make a new array preset to size 20

ary = Array.new(20)

how to loop through an array

ary.each do put i end

how to return array size

ary.size

what does gets do

asks user for input but on a new line

what is gets.chomp

asks usr for input all on the same line

when are blocka arguments used

at the beginning of thr block

when is END ran?

at the end of the program

what might before_filter be good for

authenticating users

when is BEGIN ran

before program runs

make a user to check the terms of service before a controller is ran

before_action :check_terms_of_service

#make a user a log in before a controller is ran

before_filter :authenticate_user!

begin/end/while loop

begin code end while conditional

break

break out of loop or function

to call a method in ruby just

call its name

call backs

callbacks- a callbacki s any executable code that is passed as an argument to other code, which is expected to call back (execute) the argument at a given time

all constant names must be

capitalized

constants are always

capitalized

module names must be

capitalized

how do we format cacses

case variable name when variable option command else command end

what might before_action be good for calling

checking terms of service

double indicated

clasd method

what type of @@variable is this

class variable

while modifier format

code while condition

how to make hash containers

colors= { "red" => 1, "blue" =>}

routers

computers devoted to moving packets

what is ERB

embedded ruby

!(true && true)

false

!true

false

false && false

false

false && true

false

false || false

false

nil is

false

not (false || true)

false

not (true || false)

false

not (true || true)

false

true && false

false

until loop execute while the conditional is

false

what are the entities within tables called?

fields

how to close a file in ruby

file.close

how to read the contents of a file

file.read

how to read just one line of the textfile in ruby

file.readline

move the read or write position to the beginning of the file

file.seek()

empty a file completely in ruby

file.truncate

write stuff into a file

file.write("stuff")

what are regular expressions used for?

finding words or patterns in text

how do you pass values to an argument

first, second, third, fourth, = ARGV

example of a Ruby forloop

for i in 0..5 puts "value of local variable is #{i} end

foo.K = Q

from foo get the K attribute and set it to Q

foo.M(j)

from foo get the M function and call it with the parameter J

deploy your google cloud app without changing the prior version

gcloud app deploy --no-promote

add route the simple way

get 'static_pages/hello'

what does gets.chomp does

get usrr input and then removes newlines or things that are not a string

how to reverse user input

gets.user

how to commit changes to github

git add. git commit -m "message" git add. git commit -m "message"

how to clone a repository onto your local machine

git clone url

how to work from a repository

git clone url cd xxx git add. git status git commit -m "statement" git push origin master

how do you deploy code to heroku in the cli

git push heroku master

how to deploy heroku code

git push heroku master

check if things worked in git

git status

to substitute one item for another

gsub(Find_word, replacement)

unless

inverse of if

until

inverse of while, executes while false

defined?

is this class, function/etc defined already

what is a GEMfile

its a Rails program dependency manager (what programs does this app need to run)

what is a gem file

its rubys dependency manager

arrayname.join

join arrays together

what does an instance variable belong to?

just that one object

class X: def M(J)

lass X has a function named m that takes a J parameter

LAN

local area network

and

logical and but lower priority than &&

RESTful design

lookups use GET PUT, POST, DELETE are used for mutation, creation deletion

class X <y

make a class named X that is-a Y

naming rules for classes in ruby

must be capitalized

naming rules for method

must be lowercase

?/n means

newline

can you define a constant within a method

no

can you define a constant within a method?

no

how do you call a method that goes with an object

objectidentifier.methodname

where is a local variable available

only inside a method

Go through some submitted parameter and only return the permitted few

params.permit( :seller_id :units :group_buyer id )

make sure a parameter was given to the controller from a broswer

params.require(:amg_order)

yield

pause and transfer control to the code block

block arguments are surrounded by

pipes

methods outside of a class are

private

methods inside of a class are

public

how do you print

puts

how do you insert variables inside or strings

puts " A is #{a}"

redo

redo a code block exactly the same

undef

remove a function defined within a class

add a root

root 'controllername#methodname'

hoe to run a ruby file

ruby test.rb

rescue

run this code if an exception happens

ensure

run this code whether an exception happens or not

belongs_to

self.inheritance_column

foo = X.new

set foo to an instance of class X

next

skip to the next element of the iterator

regular expression are surrounded by

slashes

how to compare a string to another string

str <=> other_str (results: less than: -1, same: 0, greater than: 1)

To test if an object is a string

str == obj ..if false; it isn't a string

how to capitalize a string

str. capitalize

concatenate two strings together

str.concat(str2)

make as tring with no white spaces

string.strip

how to make a string capitalized

stringname.upcase

if it starts with : its a

symbol

app/view/layouts

template files for layouts

scalability

the capability of a system, network, or pocess to handle a growing amount of work

scalability

the capability of a system, network, or process, to handle a growing amount of work

self

the current object, class, or module

Port

the end point of communication; has an IP and a protocol

what is an object

the most basic type of thing, an instance of a class

super

the parent class

what do if an case statements returb

the valur of the last expression executed

what do MySQL , MS Access" Oracle, Syvase, Informix, Postgres and SQL have in common

they are all relational database management systems

TCP stands for

transfer protocol

!(false && false)

true

!(false && true)

true

!(true && false)

true

!false

true

false || true

true

not (false || false)

true

true && true

true

true || false

true

true || true

true

while loops execute while the condition is

true

open a file

txt = open(filename, "w" )

close file

txt.close

read file

txt.read

go to the first byte of a file

txt.rewind(0)

write file

txt.write()

until loop format

until condition code change condition end

gets the first argument

user_name = ARGV.first

anybplain lowercase word in ruby is a

variable

#how to find some id in a table

variablename = tablename.find_by_id(thing to search in table)

what do controllers handle

web requests from a user

what is the format of doing a while loop

while condition do code end

WAN

wide area network

END block

will be printed last

BEGIN block

will be ran first

how should you always write constant identifiers

with uppercase letters

how do you make a new object

x = Classname.new

how to get userinput

x= gets

what is the command to enter a block called test if you are in a method called test

yield

or logic operator

||


Set pelajaran terkait

HRM Chapter 11—Total Rewards and Compensation

View Set

Chapter Seven: Current Flashpoints

View Set

Chapter 16 Nomenclature and Botanical Names

View Set

Unit 12: Nutrition and excercise

View Set

L. 7 Second Empires of Persia and India (East Asia)

View Set

DLC 203: Elements of the Army Profession

View Set

Chapter 23: Chemical and Waste Management

View Set

Anatomy 2 Unit 2 Critical Thinking

View Set