0
0
Ruby on Railsframework~10 mins

Russian doll caching 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 cache a post partial using Russian doll caching.

Ruby on Rails
<%= cache(@post) do %>
  <%= [1] 'post' %>
<% end %>
Drag options to blanks, or click blank then click option'
Alink_to
Brender
Cform_for
Dcontent_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using link_to instead of render inside the cache block.
Forgetting to render the partial inside the cache block.
2fill in blank
medium

Complete the code to cache a collection of comments with Russian doll caching.

Ruby on Rails
<%= cache(@comments) do %>
  <%= [1] @comments %>
<% end %>
Drag options to blanks, or click blank then click option'
Aform_for
Blink_to
Crender
Dcontent_tag
Attempts:
3 left
💡 Hint
Common Mistakes
Using link_to or other helpers instead of render.
Not rendering the collection inside the cache block.
3fill in blank
hard

Fix the error in the code to properly use Russian doll caching for a post and its comments.

Ruby on Rails
<%= cache(@post) do %>
  <h2><%= [1] %></h2>
  <%= render @post.comments %>
<% end %>
Drag options to blanks, or click blank then click option'
Apost.title
Bpost[:title]
Ctitle
D@post.title
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variable post instead of @post.
Using incorrect syntax like post[:title].
4fill in blank
hard

Fill both blanks to use a cache key with a timestamp for Russian doll caching.

Ruby on Rails
<%= cache([@post, [1]]) do %>
  <%= render 'post', post: @post %>
<% end %>
Drag options to blanks, or click blank then click option'
A@post.updated_at
B@post.created_at
C@post.id
DTime.now
Attempts:
3 left
💡 Hint
Common Mistakes
Using @post.created_at which doesn't change after creation.
Using Time.now which changes every time and breaks caching.
5fill in blank
hard

Fill all three blanks to implement nested Russian doll caching for a post and its comments.

Ruby on Rails
<%= cache(@post) do %>
  <h1><%= [1] %></h1>
  <ul>
    <% @post.comments.each do |comment| %>
      <li><%= [2](comment) do %>
        <p><%= [3] %></p>
      <% end %></li>
    <% end %>
  </ul>
<% end %>
Drag options to blanks, or click blank then click option'
A@post.title
Bcache
Ccomment.body
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Not caching each comment individually.
Using render instead of cache for comments.
Not displaying the comment body correctly.