Liked Products Page


Collapse Content

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

Account Info

Since you now have a personal page for the user, you can add some additional account info and links to the page. Here are 3 things to add:

  1. Move the Logout link from your navigation bar to my_page.
  2. Display the email of the logged-in user
  3. Add a link for a user to edit their account info. Open /rails/info/routes and find the named path that Devise provides for this purpose.
Complete my_page

After removing the link to logout from the top of your site, can you add a link to my_page? It should only be displayed to logged-in users.

_header code

my_page should look something like this:

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