0
0
Ruby on Railsframework~10 mins

Layouts and content_for 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 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'
A<%= yield %>
B<%= content_for :header %>
C<%= render 'shared/footer' %>
D<%= link_to 'Home', root_path %>
Attempts:
3 left
💡 Hint
Common Mistakes
Using content_for instead of yield for main content.
Forgetting to include yield in the layout.
2fill in blank
medium

Complete 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'
Aprovide
Byield
Crender
Dcontent_for
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.
3fill in blank
hard

Fix 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'
A<%= yield :sidebar %>
B<%= content_for :sidebar %>
C<%= render :sidebar %>
D<%= provide :sidebar %>
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.
4fill in blank
hard

Fill 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'
A<%= content_for :header %>
B<%= yield %>
C<%= yield :header %>
D<%= content_for :main %>
Attempts:
3 left
💡 Hint
Common Mistakes
Using content_for in the layout instead of yield.
Mixing up named and default content blocks.
5fill in blank
hard

Fill 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'
Acontent_for
BThis is the main page content.
Cyield
Dprovide
Attempts:
3 left
💡 Hint
Common Mistakes
Using provide instead of content_for to define header.
Not using yield to output main content.