Chapter 2 Flashcards

1
Q

when you create new app, what git steps do you need to take:

A

git init
git add -A
git commit -am “initialize repository”

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

connect new app to github:

A

create new repository on github manually.
then:
git remote add origin https://github.com/Saweel/toy_app.git

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

how to remove origin from git repo and set another one

A

git remote set-url origin newURL

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

data model

A

representation of the structures needed by our application. conceptual model of how data items relate to each other

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

data model for toy_app

A

microblog with users and short microposts.

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

data model for users:

A

unique integer identifier id, name, email

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

data model for microposts:

A

id and a content field for the text. also a user_id to associate each micropost with a particular user

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

User resource:

A

think of users as objects that can be created, read, updated, deleted through the web via the HTTP protocol (created using scaffoldin)

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

generate user with name and email using scaffolding

A

rails generate scaffold User name:string email:string

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

update the database in rails after creating a new user data model

A

bundle exec rake db:mirate

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

what is “make”?

A

unix, make utility is used to build executable programs from source code.

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

Rake:

A

rake is rubys make, a make-like language written in ruby. uses rake for little administrative tasks necessary developing database-backed web application.

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

bundle exec rake -T db

A

list of database tasks

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

bundle exec rake -T

A

all the rake tasks available

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

URL/users

A

index, page to list all users

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

URL/users/1

A

show, page to show user with id 1

17
Q

URL/users/new

A

new, page to make new user

18
Q

URL/users/1/edit

A

edit, page to edit user with id 1

19
Q

what is the 1 mean in URL/users/1

A

the id attribute of the user

20
Q

in terms of MVC, describe the results of a typical browser hit- a visit to the user index page at /users (BIG ANSWER)

A
  1. browser issues request for the /users URL
  2. Rails routes /users to the index action in the Users controller
  3. index action asks User model to retrieve all users
  4. User models pulls all the users from the database
  5. User model returns the list of users to the controller
  6. controller captures users in the @users variable, which is passed to the index view
  7. view uses embedded ruby to render the page as HTML
  8. controller passes the HTML back to the browser
21
Q

routes.rb, explain “resources :users”

A

creates the mapping of user URLs to controller actions for the User resource.

22
Q

add a root route for users

A

root ‘users#index’

23
Q

rails: index,new,show,edit correspond to pages. describe create, update, and destroy actions

A

they dont typically render pages (although they can); main purpose is to modify information about users in the database

24
Q

index,show,new,create,edit,update,destroy are actions in users_controller. describe the http request for each

A
index -> get
show -> get
new -> get
create -> post
edit -> get
update -> patch
destroy -> delete
25
REST define (simple)
REpresentational State Transer (rest). architectual style for developing distributed, networked systems and software applications.
26
what does REST mean in the context of rails
application components(users and microposts) are modeled as resources that can be created, read, updated, and deleted - operations that correspond both to the CRUD operations of relational database and to the four fundamental HTTP request methods: POST, GET, PATCH, DELETE.
27
@users
variables with @, are instance variables, and are automatically available in the views
28
iterates through each object stored in @users
29
weaknesses of this User resource
``` no data validations no authentication no tests no style or layout no real understanding ```
30
generate a micropost with a user id and content text
rails genrate scaffold Micropost content:text user_id:integer
31
validate micropost to accept 140 characters for the content
in micropost.rb: | validates :content, length: { maximum: 140 }
32
create associations between user having many microposts and microposts belonging to one user
``` user.rb: has_many :microposts ------------------------- micropost.rb: belongs_to :user ```
33
class User
User model inherits from ActiveRecord::Base, which is a base class for models provided by ActiveRecord (which lets us gain the ability to communicate with the database, treat database columns as ruby attributes, ect.)
34
class UsersController
User inherits from ApplicationController, which inherits from ActionController::Base (controllers gain large amounts of functionality by inhering from a base class, including ability to manipulate model objects, filter inbround HTTP requests, render views as HTML.)
35
heroku wont work if you just push it. what must you do so the app works correctly (hint: database)
you need to get the applications database to work, so you need to migrate the production database: heroku run rake db:migrate
36
scaffolding strengths:
``` high level overview of rails introduction to mvc first taste of REST beginning data modelling live, database-backed web application in production ```
37
scaffolding weaknesses:
``` no custom layout no static pages (home or about) no user passwords no images no login no security no automatic user/micropost association no notion of following no micropost feed no meaninful tests NO REAL UNDERSTANDING ```