Chapter 2 Flashcards
when you create new app, what git steps do you need to take:
git init
git add -A
git commit -am “initialize repository”
connect new app to github:
create new repository on github manually.
then:
git remote add origin https://github.com/Saweel/toy_app.git
how to remove origin from git repo and set another one
git remote set-url origin newURL
data model
representation of the structures needed by our application. conceptual model of how data items relate to each other
data model for toy_app
microblog with users and short microposts.
data model for users:
unique integer identifier id, name, email
data model for microposts:
id and a content field for the text. also a user_id to associate each micropost with a particular user
User resource:
think of users as objects that can be created, read, updated, deleted through the web via the HTTP protocol (created using scaffoldin)
generate user with name and email using scaffolding
rails generate scaffold User name:string email:string
update the database in rails after creating a new user data model
bundle exec rake db:mirate
what is “make”?
unix, make utility is used to build executable programs from source code.
Rake:
rake is rubys make, a make-like language written in ruby. uses rake for little administrative tasks necessary developing database-backed web application.
bundle exec rake -T db
list of database tasks
bundle exec rake -T
all the rake tasks available
URL/users
index, page to list all users
URL/users/1
show, page to show user with id 1
URL/users/new
new, page to make new user
URL/users/1/edit
edit, page to edit user with id 1
what is the 1 mean in URL/users/1
the id attribute of the user
in terms of MVC, describe the results of a typical browser hit- a visit to the user index page at /users (BIG ANSWER)
- browser issues request for the /users URL
- Rails routes /users to the index action in the Users controller
- index action asks User model to retrieve all users
- User models pulls all the users from the database
- User model returns the list of users to the controller
- controller captures users in the @users variable, which is passed to the index view
- view uses embedded ruby to render the page as HTML
- controller passes the HTML back to the browser
routes.rb, explain “resources :users”
creates the mapping of user URLs to controller actions for the User resource.
add a root route for users
root ‘users#index’
rails: index,new,show,edit correspond to pages. describe create, update, and destroy actions
they dont typically render pages (although they can); main purpose is to modify information about users in the database
index,show,new,create,edit,update,destroy are actions in users_controller. describe the http request for each
index -> get show -> get new -> get create -> post edit -> get update -> patch destroy -> delete