w4d2 Flashcards
What is the view responsible for?
Rendering the HTML to return to the client browser.
What are the two methods to create an HTTP response?
render (create a full response) and #redirect_to (tell the client to make a new HTTP request for a different resource)
What happens to instance variables set in the controller?
They are made available in the template that they call.
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
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
What is the helper to return a user to their previous page?
redirect_to :back
T/F: #render and #redirect_to act like the ‘return’ keyword in that they terminate execution of the function.
F; evaluation will continue