Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to redirect to the home page in a Rails controller.
Ruby on Rails
def index [1] :root_path end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect_to causes the page not to change URL.
Using send or respond_with are not for redirecting.
✗ Incorrect
In Rails, redirect_to sends the browser to a different URL.
2fill in blank
mediumComplete the code to render the 'show' template in a Rails controller.
Ruby on Rails
def show [1] 'show' end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect_to instead of render changes the URL.
Using send or respond_with are not for rendering templates.
✗ Incorrect
Use render to display a template without changing the URL.
3fill in blank
hardFix the error in the code to redirect to the 'new' action.
Ruby on Rails
def new [1] new_path end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect_to causes no URL change.
Using send or respond_with are incorrect here.
✗ Incorrect
To redirect to a path, use redirect_to with the path helper.
4fill in blank
hardFill both blanks to render the 'edit' template with status 404.
Ruby on Rails
def edit [1] 'edit', status: [2] end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect_to instead of render when showing a template.
Using status 200 instead of 404 for error.
✗ Incorrect
Use render to show a template and set HTTP status with status:.
5fill in blank
hardFill all three blanks to redirect to 'root_path' with a flash notice and status 303.
Ruby on Rails
def home [1] [2], notice: 'Welcome!', status: [3] end
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect_to for redirecting.
Forgetting to add the flash notice or status code.
✗ Incorrect
Use redirect_to with the path, flash notice, and HTTP status code.