Skip to content
This repository was archived by the owner on Aug 8, 2019. It is now read-only.

Commit 8f67ebd

Browse files
author
condef5
committed
Render favorite clubs by user
1 parent 660227a commit 8f67ebd

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

api/app/controllers/clubs_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ class ClubsController < ApplicationController
22
before_action :set_club, only: [:show, :update, :destroy]
33

44
def index
5-
render json: Club.all
5+
if params[:favorites].present?
6+
render json: current_user.clubs
7+
else
8+
render json: Club.all
9+
end
610
end
711

812
def show

api/app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ class User < ApplicationRecord
44
has_many :bookings
55

66
has_many :favorites, dependent: :destroy
7+
has_many :clubs, through: :favorites
78

89
validates :email, :name, :role, presence: true
910
validates :email, uniqueness: true

0 commit comments

Comments
 (0)