w4d3 - rails views Flashcards

1
Q

How do you validate uniqueness of a combination?

A

validates :attribute, uniqueness: { scope: :attribute2 }

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

What do views do?

A

Generate and populate the Response object

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

What context is a view evaluated in?

A

the controller

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

How do you render a view named show.html.erb?

A

render :show

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

How do you delete the current line in atom?

A

CMD + X

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

What’s the relationship between the new/create actions?

A

new - render a form

create - receive the form data and act on it

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

What’s the relationship between the edit/update actions?

A

edit - renders the form

update - receives form data and acts on it

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

What params would you send into a url helper?

A

wildcards

note that if you send in a model, its id will be populated automatically

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

What are the two ways of setting up a label?

A

For:
[label for=’id_of_thing’]body[/label]

Subling/wrap:
[label]body[input type=’text’/][/label]

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

What’s the difference between #update_attributes and #update?

A

They’re the same (alias for one another)

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

Where do you generally redirect to?

A

The model_url helper, where model is the name of the model

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

How can a form send an array back within the post params?

A

input name=’model[array_name][ ]’

Use this multiple times within the same form.

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

What’s the primary function of cookies?

A

To preserve state between HTTP requests

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

What are the 2 primary distinctions between hashing functions and cryptographic hashing functions?

A
  1. Speed. Cryptographic is slower.

2. Collisions. Cryptographic creates far fewer collisions.

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

How do you see the class inheritance path for an object?

A

objectname.class.ancestors

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

How do you access cookies that are stored only until the next request cycle?

How would you render this in a view?

A

flash[:some_error] = ‘whatever’

[%= flash[:some_error] %]

17
Q

What’s the principle behind CSRF protection?

A

Each form should have a param with a unique code that is associated with the user’s session.

When a form is submitted, if the code does not match up, we assume a CSRF attempt and raise an error.

18
Q

How does rails implement CSRF protection?

A

in every one of your forms, you add an input/hidden with

name=”authenticity_token”

and

value =
[%= form_authenticity_token %]

19
Q

How do you enable automatic CSRF protection per controller? Per site?

A
  • -per controller:
    self. per_form_csrf_tokens = true

–per site:
config/application.rb:
Rails.configuration.action_controller.per_form_csrf_tokens = true