I’m using Devise for user authentication.
We can use Devise’s current_user
and Ruby’s where method to find the user’s favorites.
class BookmarkController < ApplicationController
def index
@user = current_user
@bookmarks = Bookmark.where(user_id: @user.id).all
end
end
In the view:
<% @bookmarks.each do |bookmark| %>
<%= bookmark.name %>
<% end %>