Chapter 3 Flashcards
bundle update
update the gems to make sure the versions match
git mv README.rdoc README.md
changing the format from RDoc to Markdown using git
git commit -am
(-a) all changes, (-m) message
note*: make sure to commit everything before deploying or else you might get an error.
ok
generate a controller to handle static pages names “StaticPages” with a plan to make actions for a home page and help page
rails generate controller StaticPages home about
rails s
rails server shortcut
rails c
rails console shortcut
rails g
rails generate shortcut
bundle
bundle install shortcut
rake
rake test shortcut
when you add a branch, what is a good next step to do?
push to remote repository
git status
git add -A
git commit -m “add static pages controller”
git push -u origin static-pages
subsequent pushes can omit the arguments (git push)
why StaticPages generates static_pages_controller.rb
convention in rails to use snake case. (rails generator converts camelcase to snake using the underscore method)
you generated a controller; how do you undo it?
rails destroy controller StaticPages home help
undo rails generate model User name:string email:string
rails destroy model User
undo bundle exec rake db:migrate
bundle exec rake db:rollback
rollback all the way to beginning
bundle exec rake db:migrate VERSION=0
router
creates the correspondence between URLs and web pages
get ‘static_pages/home
maps requests for the URL/static_pages/home to the home action in the Static Pages controller. responds to GET requect
HTTP
hypertext transfer protocol. basic operations: GET, POST, PATCH, DELETE (operations between client computer and a server)client: chrome, firefox, server:apache nginx.
HTTP operations define:
GET used for reading data on the web (get a page).everytime you visit a page, your browser submits a GET request. POST request sent by browser wen you submit a form. in rails (POST typically used for creating things, also for updates). PATCH and DELETE: update and destroy things on the remote server.
GET request example
visit a site like google.com
POST request example
submit a registration form creates a new user on the remote site
classes in rails
used to organize functions
def home end
in ruby, this would do nothing. but since in inherits from ApplicationController, the behavior of this method is specific to rails. when visiting URL/static_pages/home, rails looks for static pages controller and executes the code in home action, then renders a view.