Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a layout that yields the main content.
Ruby on Rails
<html>
<body>
[1]
</body>
</html> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using content_for instead of yield for main content.
Forgetting to include yield in the layout.
✗ Incorrect
The <%= yield %> statement in a layout outputs the main content of the view using that layout.
2fill in blank
mediumComplete the code to define a named content block called :sidebar in a view.
Ruby on Rails
<% [1] :sidebar do %>
<p>This is the sidebar content.</p>
<% end %> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using yield instead of content_for to define content blocks.
Using provide which is similar but not the correct helper here.
✗ Incorrect
The content_for helper defines a named content block that can be used in layouts.
3fill in blank
hardFix the error in the layout to render the :sidebar content block if it exists.
Ruby on Rails
<div class="sidebar"> [1] </div>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using content_for in the layout to output content.
Using render or provide which do not output named content blocks.
✗ Incorrect
To render a named content block in a layout, use yield with the block's name.
4fill in blank
hardFill both blanks to define a layout that includes a header and yields main content.
Ruby on Rails
<header> [1] </header> <main> [2] </main>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using content_for in the layout instead of yield.
Mixing up named and default content blocks.
✗ Incorrect
Use yield :header to output the header content block and yield for main content.
5fill in blank
hardFill all three blanks to define a view that sets header content and main content.
Ruby on Rails
<% [1] :header do %> <h1>Welcome</h1> <% end %> <p>[2]</p> <%= [3] %>
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using provide instead of content_for to define header.
Not using yield to output main content.
✗ Incorrect
Use content_for to define header, plain text for main content, and yield to output main content in layout.