Chapter 9 Flashcards
For the Users resource, if ‘new’ corresponds to GET and ‘create’ corresponds to POST, what do edit (a form) and update correspond to?
GET and PATCH, respectively
When we see repeated code in a view, what is a good thing to do?
Make it into a partial.
In an a tag, what is a trick to get the browser to open the link in a new tab?
Use ‘_blank’
a href=”http://gravatar.com/emails” target=_blank
In form_for, how does Rails know whether to send a POST (create new user) or PATCH (update user).
Rails decides which one depending on the boolean value of #new_record?
In TDD, is it better to check if an app handles correct or incorrect information first?
Catch incorrect info first, then you can ensure it does the right thing with the correct data; easier than doing this the other way around.
What is the difference between authentication and authorization?
In the context of web applications, authentication allows us to identify users of our site, and authorization lets us control what they can do.
What is a ‘before filter’?
Ensures that certain requirements are met before an action is carried out, such a a user being logged in to their own account before updating their information.
T/F: the ‘unless’ keyword can be used as a complement to the ‘if’ statement.
T
Explain the following controller statement:
before_action :logged_in_user, only: [:edit, :update]
A before filter that states that the user must be logged in to perform any action in the controller, but this filter only applies to the ‘edit’ and ‘update’ actions.
What is a good way to test the basic functioning of a security model?
Turn it off/comment it out and see if the application responds accordingly.
What is a URL stub, and when should it be used?
Replacing a URL with simply a ‘#’ sign; good in development when not all routes have been created yet.
What goes in db/seeds.rb ?
Values/objects to place into the database.
When might it be preferable to raise an exception when encountering an error rather than merely returning false or nil?
When you want to avoid ‘silent errors’, for example when debugging.
How do we actually insert db/seeds.rb into the database?
$bundle exec rake db:seed
What does ‘pagination’ refer to within the context of a web app?
Displaying a certain number of elements per page, and indexing each page.