all Flashcards

(64 cards)

1
Q

what is a web framework

A

give baseline tools such as routing, asset management, etc so you don’t have to start from stratch

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

what is the MVC framework

A

Model - View - Controller

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

what is an opinionated framework

A

convention over configuation . have a certain way to set up organization

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

what goes in the app file

A

models, view, controllers

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

what goes in config file

A

routes

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

what goes in db file

A

migration files, schema, seed

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

syntax for route in rails

A

get “/route”, to “route#index”

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

syntax for controller

A

class FileController < ApplicationController
def index
end
end

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

what is the Model

A

like a chef. communicates with database via Active Record

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

what is the Controller

A

like the waiter. transmits data from user to the models and back to the user to view

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

what is the view

A

like the table. where date is visible to user

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

why use rails generators

A

less time consuming
help prevent errors and debug

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

types of generator

A

rails g model - create model
rails g controller - create controller
rails g migration - create new table
rails g resources - create model, controller, migration, view folder and routes

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

syntax for rails generator

A

rails g model TableName column1 column2:integer

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

what does rail generator default to for type

A

string

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

what do you run to save a migration

A

rails db:migrate

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

syntax for seed

A

Table.create(column: “data”, column: “data”)

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

what is the basic HTTP work flow

A

client request to server (fetch)
request goes to server where router interpret request and sends message to controller to map route
controller uses model to access database
controller uses data to render view (HTML or JSON)
server returns response

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

Which name is singular and which is plural in model and controller names

A

model = singular
controller = plural

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

what is rails is like binding.pry

A

byebug

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

Process for Dynamic Routes

A

routes that include parameter
routes send to controller
get instance associated with params

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

static routes

A

always have fixed routes (/user)

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

dynamic routes

A

render different data based on the parameters (/user/:id)

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

what does the code in controller look like for dynamic routes

A

def show
user = user.find(param [:id])
render json: user
end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
what do static routes look like in controller
def index users = user.all render json: users end
26
what are the 2 ways to custom render data in the controller
selecting specific with only: [:id, :name, :address] using exclude to state which ones not to add except: [:created_at, :updated_at]
27
how to include methods in the controller that will be sent to user
add methods to the render json render json: user, except: [:created_at], methods: [summary]
28
syntax for writing error messages in controller
else render json: {error: 'User not found'}, status: :not_found
29
what is REST
standardized naming pattern used across many program languages to help developers determine how routing should be created it is the standard way of mapping CRUD actions from the HTTP methods
30
7 routes that are apart of REST
index | get | display all objects new | get | form to create new object create | post | creates new object on server show | get | display specific object edit | get | form to edit specific object update | patch | update specific object on server destroy | delete | deletes specific object
31
how do you see all the routes listed in terminal
rails routes
32
what does resource do
in the routes file is creates all 7 routes
33
to select which routes using resource
resource: class , only [:index, :create, :delete]
34
what do strong params do
method that allows only certain parameters
35
how do create strong params
def create user = User.create(user_params) render json: user, status: :created end private def user_params params.permit(:name, :email) end end
36
why use strong params
stops mass assignment cleaner code
37
how to add column using migration
rails g migration AddColumnToClass column:integer
38
controller syntax for update existing element
def update user = User.find_by(id: params [:id]) if user user.update(user_params) render json: user else render json: {error: "User not found"}, status: :not_found end private def user_params params.permit(:name, :email, :password) end end
39
what are validations in rails
special methods calls that go at thetop of model class definitions and prevent them from being saved to database if the data isn't correct
40
why do we have validations
protects database from bad data
41
when are validations checked
when adding or updating data through ruby/rails
42
what is syntax for setting up validations
2 arguments the attribute and how to validate validates :name, presence: true
43
how do you trigger validations without touching database
.valid? method def create user = User.create(user_params) if user.valid? render json: user, status: :created else render json: {errors: person.errors.full_messages}, status: :unprocessable_ entity end end
44
what are built in validators
length - validates :name, length:{minimum: 2} uniqueness - validates :email, uniqueness: true
45
controller validations manually with if else using valid? syntax
def create user = User.create(user_params) if user.valid? render json: user, status: :created else render json: {errors: bird.errors}, status: :unprocessable entity end end
46
how do you format error messages
user.errors user.errors.full_messages
47
steps for creating rails API
1. generate rails application 2. create model 3. migrations 4. controller 5. routes 6. seed database 7. set up routes
48
where do you debug 404 error
in browser under network tab and then preview tab
49
where do you look at syntax error
return JSON response in controller and frontend fetch
50
where do you look server error
in server log: it gives error itself and file/name of error
51
what do active record associations do
allow us to connect complex networks of models
52
how are models connected
with foreign keys
53
how do you setup many to many
with a join table that has foreign key from both models
54
the join table for many to many would have
foriegn keys from both tables and belongs_to: in the model
55
in the many to many relationship what goes into the models that both have many
has_many :join_table has_many :other_table, through: :join_table
56
how do you show associated data
use include: :join_table
57
how do you delete assocaited data
dependent: :destroy
58
what are cookies
small pieces of information that are sent from the server to the client and stored in client
59
what do cookies help with
making HTTP stateful
60
what do cookies store
sessions information such as login, shopping cart, location, personalization, tracking information
61
what do you use in the controllers to save cookies
sessions controller
62
what is authentication
application confirm users are who they say they are
63
what is the flow for authentication
user uses login form on submit a post request is sent routes to post "/login", to "sessions#create" session controller set cookie as users id into session hash
64
what is the session controller create syntax
def create user = User.find_by(username: params[:username]) session[:user_id] = user.id render json: user end end