w4d2 Flashcards

1
Q

What is the view responsible for?

A

Rendering the HTML to return to the client browser.

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

What are the two methods to create an HTTP response?

A

render (create a full response) and #redirect_to (tell the client to make a new HTTP request for a different resource)

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

What happens to instance variables set in the controller?

A

They are made available in the template that they call.

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

What is wrong with the following code and how can it be ameliorated?

def show
  @book = Book.find(params[:id])
  if @book.special?
    render :special_show
  end

render :regular_show
end

A

render will be evaluated more than once and will throw an error. It can be fixed by ensuring that render is only encountered once in the program flow:

def show
  @book = Book.find(params[:id])
  if @book.special?
    render :special_show
  else
    render :regular_show
  end
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the helper to return a user to their previous page?

A

redirect_to :back

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

T/F: #render and #redirect_to act like the ‘return’ keyword in that they terminate execution of the function.

A

F; evaluation will continue

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