Chapter 9 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

For the Users resource, if ‘new’ corresponds to GET and ‘create’ corresponds to POST, what do edit (a form) and update correspond to?

A

GET and PATCH, respectively

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

When we see repeated code in a view, what is a good thing to do?

A

Make it into a partial.

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

In an a tag, what is a trick to get the browser to open the link in a new tab?

A

Use ‘_blank’

a href=”http://gravatar.com/emails” target=_blank

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

In form_for, how does Rails know whether to send a POST (create new user) or PATCH (update user).

A

Rails decides which one depending on the boolean value of #new_record?

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

In TDD, is it better to check if an app handles correct or incorrect information first?

A

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.

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

What is the difference between authentication and authorization?

A

In the context of web applications, authentication allows us to identify users of our site, and authorization lets us control what they can do.

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

What is a ‘before filter’?

A

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.

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

T/F: the ‘unless’ keyword can be used as a complement to the ‘if’ statement.

A

T

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

Explain the following controller statement:

before_action :logged_in_user, only: [:edit, :update]

A

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.

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

What is a good way to test the basic functioning of a security model?

A

Turn it off/comment it out and see if the application responds accordingly.

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

What is a URL stub, and when should it be used?

A

Replacing a URL with simply a ‘#’ sign; good in development when not all routes have been created yet.

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

What goes in db/seeds.rb ?

A

Values/objects to place into the database.

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

When might it be preferable to raise an exception when encountering an error rather than merely returning false or nil?

A

When you want to avoid ‘silent errors’, for example when debugging.

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

How do we actually insert db/seeds.rb into the database?

A

$bundle exec rake db:seed

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

What does ‘pagination’ refer to within the context of a web app?

A

Displaying a certain number of elements per page, and indexing each page.

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

What are the steps involved in adding a new attribute to a model?

A

Generate a database migration, containing the value name and data type, then run the migration.

17
Q

Y/N: If the ‘admin’ attribute is a boolean value, should it be false by default? Why?

A

Yes, for obvious security reasons.

18
Q

When adding a boolean attribute through a db migration, what method will rails automatically add to the model?

A

A ‘?’ method.

i.e. #admin?

19
Q

Explain the importance of the following code:

def user_params
      params.require(:user).permit(:name, :email, :password,
                                   :password_confirmation)
    end
A

This code returns a version of the params hash with only the permitted attributes (while raising an error if the :user attribute is missing).

This returns a list of strong parameters, which help prevent malicious activity.

Note in particular that admin is not in the list of permitted attributes. This is what prevents arbitrary users from granting themselves administrative access to our application.

20
Q

What is so important about the following before filter?

before_action :admin_user, only: :destroy

A

It ensures that only admins can issue a DELETE request (the ‘destroy’ action), otherwise any arbitrary user could do so.