Chapter 7 Flashcards

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

Explain the following erb code:

A

Adds debug information to the view if it is in a development environment.

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

What is a mixin in Sass?

A

It allows a group of css rules to be packaged up and used for multiple elements.

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

What is so powerful about the following route example?

resources :users

A

It creates a large number of RESTful actions and routes for the given resource.

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

What is the params variable?

A

A hash containing a variety of information about a model

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

What is the byebug gem and how is it used.

A

When the ‘debugger’ keyword is inserted into a controller action and that controller action is called, the rails server will bring up a debugging prompt which accepts queries about the current state of the application.

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

What is a Gravatar?

A

A globally recognized avatar. Gravatar is a free service that allows users to upload images and associate them with email addresses they control. As a result, Gravatars are a convenient way to include user profile images without going through the trouble of managing image upload, cropping, and storage; all we need to do is construct the proper Gravatar image URL using the user’s email address and the corresponding Gravatar image will automatically appear.

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

In the Rails console, how can the attributes of a database object be updated?

A

object.update_attributes(options hash)

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

Say we want to reset our database, how do we do it?

A

$ bundle exec rake db:migrate:reset

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

What is the function to create a form in erb?

A

form_for(controllerVariable){block}

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

Rails generated the following form HTML tag; explain it:

A

Here the class and id attributes are largely irrelevant; what’s important is action=”/users” and method=”post”. Together, these constitute instructions to issue an HTTP POST request to the /users URL.

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

What is an authenticity token, commonly seen in generated Rails HTML forms?

A

A value Rails sends along with user submitted data to prevent cross-site request forgery (CSRF) attacks.

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

Why is #save useful for if/else loops?

A

It returns a boolean of its success.

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

What is mass assignment, and why is it insecure?

A

Mass assignment is the initialization of a Ruby variable with a hash of values. This is insecure because, in the case of a POST HTTP request, an attacker could simply append something like ‘admin: true’ to a request to create a new user in order to gain control of a site!

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

Explain the following code:

params.require(:user).permit(:name, :email, :password, :password_confirmation)

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).

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

What is best practice when using strong parameters (i.e. permitted and required attributes)?

A

Create a private method names user_params which returns the strong parameters, as a means of abstraction.

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

T/F: When adding validations in the model definitions, Rails provides default error messages when these fail.

A

T

17
Q

How can we access validation error messages?

A

model.errors.full_messages

18
Q

What does the following code do, and where is the function located:

pluralize(2, “woman”)

A

returns ‘2 women’

located in
ActionView::Helpers::TextHelper

19
Q

What does the Sass function @extend do?

A

Extends a class.

@extend .existing-class;

20
Q

How do we generate a test for a form to see if it takes correct input?

A

$ rails generate integration_test test_name

21
Q

T/F: The default behavior of a Rails controller action is to render the corresponding view.

A

T; providing the (erb) template corresponding to the action has been created.

22
Q

What can we do if we want to route an action to another view other than the (default) corresponding one?

A

Use the redirect_to function, which takes a URL as an argument.

23
Q

What is the ‘flash’ hash?

A

It displays the contents of a key, such as :success when creating a new user, on a page when redirected to it, but disappears when the page is reloaded or another page is visited.

24
Q

What are the four flash classes supported by Bootstrap CSS?

A

success, info, warning, and danger.

25
Q

How is the flash hash used?

A

It is iterated through, and each message is displayed via erb.

26
Q

What does Secure Sockets Layer (SSL) do?

A

Encrypts information sent as traffic from browser to server and vice-versa

27
Q

How can SSL be easily turned on site-wide?

A

Uncomment ‘config.force_ssl = true’ in the config/environments directory in the script for the environment you desire.