Chapter 3 Flashcards

1
Q

where are rails actions?

A

in the controller

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

switch to branch “static-pages”

A

git checkout -b static-pages

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

how can we generate a controller?

A

rails generate command to generate scaffolding

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

steps to make a controller to handle static pages

A

create StaticPages controller using generate. plan to make actions for home page, help page and about page.
$ rails generate controller StaticPages home help

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

$ rails generate conroller StaticPages home help

A

generates StaticPages controller with actions for home and help

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

scaffolding

A

generate major pieces of an application to create models, views, and controllers for a new resource

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

rails g

A

rails generate shortcut

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

rails c

A

rails console shortcut

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

bundle install

A

bundle shortcut

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

rake test

A

rake shortcut

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

git push -u origin static-pages

A

pushes topic branch up to github

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

destroy controller StaticPages:

A

rails destroy controller StaticPages home help

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

generate a model using scafffolding

A

rails generate model User name:string email:string

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

undo model generated User

A

rails destroy model User

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

bundle exec rake db:migrate

A

change the state of the database

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

undo db:migrate

A

bundle exec rake db:rollback (undo a single migration)

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

route file

A

responsible for implementing the router(defining the correspondence between URLs and web pages).

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

get ‘static_pages/home’

A

located in cofig: maps requests for the URL /static_pages/home to the home action in the Static Pages controller.

19
Q

get ‘static_pages/home’ what is get

A

using get we arrange the route to respond to a GET request, HTTP

20
Q

http

A

basic operations get, post, patch, and delete. operations between a client(chrome firefox) and a server(apache or nginx). emphasis on http verbs is typical of web frameworks influenced by the rest architecture.

21
Q

get method

A

reading data on the web. just means ‘get a page’. everytime you visit google your browser submits a get request

22
Q

post method

A

request sent by your browser when you submit a form. in rails, post are typically used for creating things(http also allows post to perform updates.

23
Q

patch method

A

updating things on remote server

24
Q

delete mthod

A

destroy things on remote server

25
classes in rails
organize functions like home and help action which are defined using def keyword
26
``` def home end in ruby this method is empty. is that true for Rails? ```
because it inherits ApplicationController the behavior of its methods is specific to rails. when visitin th url, rails executes the code inthe method AND renders the view. if method is empty, all it does is render the view.
27
TDD
test-driven development, programmers writes failing tests first, and then writes the application code to get the tests to pass
28
benefits of testing
1. protects against regressions where a functioning feature stops working for some reason 2. test allow code to be refactored(changing its form without changing its function) 3. tests act as a client for the application code helping determine its design and its interface
29
when to test first(or test at all)
1. if test is short compared to code, write test first 2. when desired behavior of app isnt clear, write application code first. 3. because security is a top priority, write test for security model first 4. whenever a bug is found, write a test to reproduce it and protect against regressions, then write the code to fix it. 5. against writing test code for html structure 6. write tests before refactoring code --usually write controller and model tests first and integration tests(functionality) second
30
test "should get home" do get :home assert_response :success end
lets test the home page by using get request to the home action and then making sure we receive a success status code in response
31
run test suite to verify tests currently pass
bundle exec rake test
32
ActionController::UrlGenerationError: | No route matches {:action=>"about", :controller=>"static_pages"}
no route matches the desired action/controller combination which is a hind that we need to add a line to the routes file
33
AbstractController::ActionNotFound: | The action 'about' could not be found for StaticPagesController
missing about action in static pages controller, which we can add
34
ActionView::MissingTemplate: Missing template static_pages/about
indicates a missing template, which in the context of rails is essentially the same thing as a view.
35
touch app/views/static_pages/about.html.erb
although touch is designed to update the modification of a file or directory without otherwise affecting it, as a die-effect it creates a new file if one doesnt exist
36
assert_select "title", "Home | Ruby on Rails Tutorial Sample App"
checks for the presence of a tag containing the string.
37
DRY
Dont Repeat Yourself principle: our html paes contained almost identical titles, common parts to all three, and an entire HTML skeleton structure is repeated on each page. we'll DRY out our code by removing repitition
38
ERb
embedded ruby, primary template system for including dynamic content in web pages
39
rails function provide fr titles
special rails function to set different titles on each page
40
indicates using that rails should call the provide function and associate the string "Home" with the label :title, then we use yield funtion in ruby to insert the title into the template
41
| Ruby on Rails Tutorial Sample App
insert title label string into parts of html code
42
responsible for inserting the contents of each page into the layout. converts the contents of home.html.erb to HTML and then inserts it in place of
43
csrf_meta_tags
prevents cross-site request forgery (CSRF), a type of malicious web attack
44
purpose of rails layout
allow the use of a common template for pages in our application, thereby eliminating duplication