Premium Content - Free Preview
Let's make a small addition and improvement to the store.
user like count
Below the like button, can you display the number of users who liked the product?
Guideline: You already declared that each product
has_many likes, so can you use this relationship to display a number?
Add this code below your buttons:
<p><%= @product.likes.size %> users like this.</p>
.size returns the number of items.
(You could also use
.size is more flexible.)
errors and bugs
What happens when someone who isn't logged in visits
/my_page? Try it out:
Rails provides a helpful error page so you can see what went wrong.