Chapter 3 Flashcards Preview

Ruby on Rails Tutorial > Chapter 3 > Flashcards

Flashcards in Chapter 3 Deck (38)
Loading flashcards...
1
Q

bundle update

A

update the gems to make sure the versions match

2
Q

git mv README.rdoc README.md

A

changing the format from RDoc to Markdown using git

3
Q

git commit -am

A

(-a) all changes, (-m) message

4
Q

note*: make sure to commit everything before deploying or else you might get an error.

A

ok

5
Q

generate a controller to handle static pages names “StaticPages” with a plan to make actions for a home page and help page

A

rails generate controller StaticPages home about

6
Q

rails s

A

rails server shortcut

7
Q

rails c

A

rails console shortcut

8
Q

rails g

A

rails generate shortcut

9
Q

bundle

A

bundle install shortcut

10
Q

rake

A

rake test shortcut

11
Q

when you add a branch, what is a good next step to do?

A

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)

12
Q

why StaticPages generates static_pages_controller.rb

A

convention in rails to use snake case. (rails generator converts camelcase to snake using the underscore method)

13
Q

you generated a controller; how do you undo it?

A

rails destroy controller StaticPages home help

14
Q

undo rails generate model User name:string email:string

A

rails destroy model User

15
Q

undo bundle exec rake db:migrate

A

bundle exec rake db:rollback

16
Q

rollback all the way to beginning

A

bundle exec rake db:migrate VERSION=0

17
Q

router

A

creates the correspondence between URLs and web pages

18
Q

get ‘static_pages/home

A

maps requests for the URL/static_pages/home to the home action in the Static Pages controller. responds to GET requect

19
Q

HTTP

A

hypertext transfer protocol. basic operations: GET, POST, PATCH, DELETE (operations between client computer and a server)client: chrome, firefox, server:apache nginx.

20
Q

HTTP operations define:

A

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.

21
Q

GET request example

A

visit a site like google.com

22
Q

POST request example

A

submit a registration form creates a new user on the remote site

23
Q

classes in rails

A

used to organize functions

24
Q
def home
end
A

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.

25
Q

test-driven development define:

A

TTD, testing technique in which the programmer writes failing tests first, and then writes the application code to get the test to pass.

26
Q

writing automated tests has 3 main benefits:

A
  1. protect against regressions, where a functioning feature stops working for some reason.
  2. allow code to be refactored
  3. test act as a client for the application code, helping determine its design and its interface
27
Q

when to write test first or after writng the code:

A

when test is short
when desired behavior isnt clear, write application code first
security: write tests first
when a bug is found, write test to reproduce it and protect against regression, then write code to fix it
lean against writing test for code likely to change.
write tests before refactoring code,

28
Q

integration tests:

A

tests functionality across models, views and controllers (chapter 7)

29
Q

test “should get home” do
get :home
assert_response :success
end

A

says lets test the home page by issuing a GET request to the home action and them make sure we receive a success status code in response (verifies via assertion that result is a success)

30
Q

execute rails test command

A

bundle exec rake test

31
Q

assert_select

A

lets us test for presence of a particular HTML tag (sometimes called a selector, hence the name)

32
Q

DRY

A

dont repeat yourself. remove repition in code (such as html code). becuase we have embedded ruby in our views, we can dry our code.

33
Q

embedded ruby

A

embeds ruby into a text document. often used to embed ruby code in an html document, similar to asp, jsp, and php. (.html.erb Erb is the primary template system for including dynamic content in web pages)

34
Q

provide(:title, “Home”);

A

indicates that rails should call the provite function and associate the string “Home” with the label :title

35
Q
A

executes the code inside, while executes it and inserts the result into the template. yield to insert the title

36
Q

application.html.erb

A

layout file allows us to factor out common structure.

37
Q

in application.html.erb layout file

A

this code is responsible for inserting the contents of each page into the layout. (converts home.html.erb to HTML and inserts it).

38
Q
A

prevents cross-site request forgery (CSRF), a type of malicious web attack