0
0
Ruby on Railsframework~10 mins

Redirect and render in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aredirect_to
Brender
Csend
Drespond_with
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.
2fill in blank
medium

Complete 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'
Aredirect_to
Brender
Csend
Drespond_with
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.
3fill in blank
hard

Fix 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'
Arender
Brespond_with
Credirect_to
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect_to causes no URL change.
Using send or respond_with are incorrect here.
4fill in blank
hard

Fill 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'
Arender
Bredirect_to
C404
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect_to instead of render when showing a template.
Using status 200 instead of 404 for error.
5fill in blank
hard

Fill 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'
Arender
Bredirect_to
Croot_path
D303
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect_to for redirecting.
Forgetting to add the flash notice or status code.