Chapter 3 Flashcards
What does running ‘bundle update’ accomplish?
Updates the gemset to match those specified by the Gemfile
What does the ‘git mv’ command accomplish?
Moves the contents of one file to another file. Since we are moving, not copying, the original file is destroyed.
How can we see Heroku’s logs to help diagnose a problem?
$ heroku logs
In making a dynamic page, what are actions/views and controllers for?
Actions/views contain only static HTML, and controllers contain sets of actions (functions) related by a common purpose.
What is the syntax for generating a controller?
$ rails genreate controller controllerName optionalAction1 optionAction2
How can we push a branch besides master to BitBucket, thereby changing the branch we are pushing?
Include the -u flag and origin parameter, and add one final argument with the name of the branch to push:
$ git push -u origin static-pages
T/F: When giving a generator a controller name, it automatically converts CamelCase to snake_case
T
Explain the following command:
$ rails destroy controller StaticPages home help
After generating this controller, we can mimic the command with the ‘destroy’ directive instead to undo changes. Note that additional command line arguments must also be added in order to be included in the rollback
How can we undo a database migration we performed with the db:migrate command?
$ bundle exec rake db:rollback
OR, to go back to the beginning:
$ bundle exec rake db:migrate VERSION=0
Explain the rule in the routes.rb file:
get ‘static_pages/home’
When we passed the ‘home’ parameter to the generator for the StaticPages controller, Rails added a route to access these pages when given as part of a URL
Furthermore, by using ‘get’ we arrange for the route to respond to a GET request
What are four of the most common HTTP operations?
GET, POST, PATCH, DELETE
Explain GET, POST, PATCH, and DELETE in the context of Rails
GET: Used to read data; sends a request from client to server to get a page
POST: Used for creating things; a request sent by client to submit a form
PATCH: Updates things on a server
DELETE: Deletes things on a server
What is Rake?
Short for Ruby make; a make-like language written in Ruby
T/F: When using scaffolding, the resulting controller uses REST architecture, whereas when only a controller is generated, not all of the REST architecture is used
T
When generating a controller, what do the additional parameters do in the controller file?
They are added as functions within the controller’s class
Since the initial function in the controller file for a page (i.e. parameter to a controller generator) is empty, how does Rails render the page?
Since the controller inherits from ApplicationController, all it needs to do is render the view (i.e. make a static page) and doesn’t need to perform any actions
What is the correspondence between actions and views?
An action like home has a corresponding view called home.html.erb.
Where are views located?
In apps/views/controllerName/pageName.html.erb
T/F: Rails must contain more than just static HTML.
F; Rails can contain just static HTML.
What is a test suite?
A collection of automated tests for test-driven development.
What are some guidelines for developing tests?
- When a test is especially short or simple compared to the application code it tests, lean toward writing the test first.
- When the desired behavior isn’t yet crystal clear, lean toward writing the application code first, then write a test to codify the result.
- Because security is a top priority, err on the side of writing tests of the security model first.
- Whenever a bug is found, write a test to reproduce it and protect against regressions, then write the application code to fix it.
- Lean against writing tests for code (such as detailed HTML structure) likely to change in the future.
- Write tests before refactoring code, focusing on testing error-prone code that’s especially likely to break.
Where does Rails store generated test scripts?
In the tests directory
What action does a generated test script use to see if a test has succeeded?
An assert statement:
test “should get home” do
get :home
assert_response :success
end
How can we run a test suite?
$ bundle exec rake test