We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 78128f0 commit 60eae20Copy full SHA for 60eae20
app/controllers/exercises_controller.rb
@@ -83,8 +83,12 @@ def add_to_cart
83
Cart.create(user: current_user)
84
end
85
cart = Cart.find_by(user: current_user)
86
- cart.exercises << @exercise
87
- redirect_to @exercise, notice: 'Exercise was successfully added to your cart.'
+ unless cart.exercises.find_by(id: @exercise.id)
+ 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
92
93
94
def exercises_all
0 commit comments