0
0
Ruby on Railsframework~10 mins

Partial templates 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 render a partial named '_menu.html.erb' inside a view.

Ruby on Rails
<%= render [1] %>
Drag options to blanks, or click blank then click option'
Apartial: 'menu'
B'menu'
Ctemplate: 'menu'
Dpartial: :menu
Attempts:
3 left
💡 Hint
Common Mistakes
Including the underscore in the partial name.
Using 'partial:' keyword incorrectly.
Using symbols instead of strings.
2fill in blank
medium

Complete the code to render a partial named '_item.html.erb' and pass a local variable 'product' to it.

Ruby on Rails
<%= render partial: 'item', locals: [1] %>
Drag options to blanks, or click blank then click option'
A{ product: @product }
B{ product => @product }
Cproduct: @product
Dproduct = @product
Attempts:
3 left
💡 Hint
Common Mistakes
Using => instead of : inside the hash.
Not wrapping the locals in curly braces.
Using assignment (=) instead of hash syntax.
3fill in blank
hard

Fix the error in rendering a collection of @products with the partial '_product.html.erb'.

Ruby on Rails
<%= render [1] %>
Drag options to blanks, or click blank then click option'
Apartial: 'product', collection: @products
Bpartial: @products
Ccollection: @products
Dpartial: 'products', collection: @product
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural partial name.
Passing collection without partial.
Mixing singular and plural variable names.
4fill in blank
hard

Fill both blanks to render a partial '_comment.html.erb' for each comment in @comments and pass each comment as a local variable named 'comment'.

Ruby on Rails
<%= render partial: [1], collection: [2], locals: { comment: comment } %>
Drag options to blanks, or click blank then click option'
A'comment'
B@comments
C'comments'
D@comment
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural partial name.
Passing a single comment instead of the collection.
Not matching local variable name with partial.
5fill in blank
hard

Fill all three blanks to render a partial '_user.html.erb' for each user in @users, pass each user as 'user', and add a spacer partial '_spacer.html.erb' between each user.

Ruby on Rails
<%= render partial: [1], collection: [2], locals: { user: user }, [3]: 'spacer' %>
Drag options to blanks, or click blank then click option'
A'user'
B@users
Cspacer_template
Dspacer_template_name
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong key for spacer partial.
Using plural partial name.
Not passing the local variable correctly.