0
0
Ruby on Railsframework~10 mins

Why views present data in Ruby on Rails - Test Your Understanding

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

Complete the code to display the user's name in the view.

Ruby on Rails
<h1>Welcome, [1]!</h1>
Drag options to blanks, or click blank then click option'
A{{ user.name }}
B@user.name
C<%= @user.name %>
Duser.name
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to use <%= %> to output data
Using JavaScript or other syntax instead of Ruby in views
2fill in blank
medium

Complete the code to loop through all posts and show their titles in the view.

Ruby on Rails
<ul>
  <% @posts.each do |[1]| %>
    <li><%= [1].title %></li>
  <% end %>
</ul>
Drag options to blanks, or click blank then click option'
Apost
Bposts
Citem
Dp
Attempts:
3 left
💡 Hint
Common Mistakes
Using plural variable names inside the block
Not matching the block variable with the collection items
3fill in blank
hard

Fix the error in the code to correctly display the user's email.

Ruby on Rails
<p>Email: [1]</p>
Drag options to blanks, or click blank then click option'
A@user.email
B<%= user.email %>
Cuser.email
D<%= @user.email %>
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting <%= %> so the code doesn't output anything
Using local variables instead of instance variables
4fill in blank
hard

Fill both blanks to create a link to the user's profile with the user's name as link text.

Ruby on Rails
<%= link_to [1], [2] %>
Drag options to blanks, or click blank then click option'
A@user.name
Buser_path(@user)
Cprofile_path
D:user
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order of arguments
Using symbols instead of path helpers
5fill in blank
hard

Fill all three blanks to display a list of product names with prices formatted as currency.

Ruby on Rails
<ul>
  <% @products.each do |[1]| %>
    <li><%= [2] %> - <%= number_to_currency([3]) %></li>
  <% end %>
</ul>
Drag options to blanks, or click blank then click option'
Aproduct
Bproduct.name
Cproduct.price
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names
Not formatting price as currency