w4d2 - rails Flashcards
What’s the naming convention for controllers?
plural and CamelCase
What’s the naming convention for views?
[name of action].html.erb
What does erb stand for?
Embedded RuBy
What’s the difference between the two erb ruby tags?
The one with the equals will be rendered. The one without will not be rendered.
What’s the name of the parent layout?
application.html.erb
What are url helper methods? Where are they defined? How do you use them?
Shortcuts for the url that will point to a particular action.
They are defined in routes.rb and can be seen via ‘rails routes’.
You use them as if they are a method, so:
redirect_to whatever_url
What causes a DoubleRenderError? What’s one way to get around it?
The cause is assuming that methods like redirect_to and render act like returns, and then using these multiple times in an action.
To get around it, place a return statement after using a conditional redirect_to/render
How do you specify which url and which method a form will submit to?
form action=”url” method=”post/get”
For PATCH/PUT:
Use the method above with ‘post’ AND THEN add a hidden input like so:
input type=”hidden” name=”_method” value=”PATCH/PUT”
What’s the general pattern for create?
Call new on a model, passing in params.
Try to save it. If it saves, we show user the show view. If it fails, we show the user the create view.
When first starting out, how do you allow rails to accept forms without auth tokens?
Comment out the protect_from_forgery line in application_controller.rb
How do you render a partial from inside of a view?
render ‘partial_name’, var1: :value1, var2: :value2, …
What’s a shortcut to render a partial for each model in a collection?
What needs to be set up for this to work?
render @mymodels
There must be a model named ‘mymodel’ AND there must be a partial named ‘_mymodel’
What’s the name of the gem that gives a REPL in the browser with the ‘fail’ keyword?
better_errors
What are the 3 places rails params come from?
query params
route URI/wildcards
POST/PATCH request data
What are the 5 aspects of a HTTP request?
method path query string header fields body