私のアプリにはアイテムがあり、make_flaggable gem を使用してそれらのアイテムを「お気に入り」としてマークできます。
すべてのユーザーが自分のお気に入りのアイテムを見ることができるページを作成したいと考えています。
どんな助けでも大歓迎です!
item.rb
make_flaggable :favorite
user.rb
make_flagger
items_controller.rb
def favorite
@current_user = User.first
@item = Item.find(params[:id])
@current_user.flag(@item, :favorite)
redirect_to @item, :notice => "Added to Your Favorites"
end
def unfavorite
@current_user = User.first
@item = Item.find(params[:id])
@current_user.unflag(@item, :favorite)
redirect_to @item, :notice => "Removed from Your Favorites"
end