Skip to content

Commit 60eae20

Browse files
committed
disabled adding same exercise multiple times
1 parent 78128f0 commit 60eae20

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/controllers/exercises_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,12 @@ def add_to_cart
8383
Cart.create(user: current_user)
8484
end
8585
cart = Cart.find_by(user: current_user)
86-
cart.exercises << @exercise
87-
redirect_to @exercise, notice: 'Exercise was successfully added to your cart.'
86+
unless cart.exercises.find_by(id: @exercise.id)
87+
cart.exercises << @exercise
88+
redirect_to @exercise, notice: 'Exercise was successfully added to your cart.'
89+
else
90+
redirect_to @exercise, alert: 'Exercise already in your cart.'
91+
end
8892
end
8993

9094
def exercises_all

0 commit comments

Comments
 (0)