Liked Products Page


Premium Content - Free Preview

Now that the Like model, relationship and methods are set up, let's create a page for users to view all their liked products. Afterwards, we'll create a button for liking products.

Create my_page

Create a page called my_page that users can visit at /my_page.

Guideline: Create a my_page controller action in UsersController and a my_page file in views/users. Create the necessary route to point to it.

The Code

Filling in my_page

Manual Sample Data
If you haven't already done so, create a few likes in the command line so you can see how my_page displays them before you even create the like button. (Make sure to create the likes for the user account you're logged in on.)

Displaying Liked Products

Add code to your my_page file to display the products for the current user. You may find the Devise current_user helper method to be useful. Can you display all the liked products with one line of code?

my_page code

End of Free Content Preview. Please Sign in or Sign up to buy premium content.

Contact Us
Sign in or email us at [email protected]