Skip to content

Commit

Permalink
fix: avoid to create check in record if check in already
Browse files Browse the repository at this point in the history
  • Loading branch information
takaishi committed Nov 16, 2024
1 parent ddb0867 commit 963e70d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions app/controllers/stamp_rally_check_ins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ def index

def new
@stamp_rally_check_point = @conference.stamp_rally_check_points.find(params[:stamp_rally_check_point_id])
@stamp_rally_check_in = StampRallyCheckIn.new({ stamp_rally_check_point_id: params[:stamp_rally_check_point_id], profile: @profile, check_in_timestamp: Time.zone.now })

if @stamp_rally_check_in.save
redirect_to(stamp_rally_check_ins_path, flash: { notice: @stamp_rally_check_point.name.to_s })
if StampRallyCheckIn.find_by(stamp_rally_check_point_id: params[:stamp_rally_check_point_id], profile: @profile).present?
redirect_to(stamp_rally_check_ins_path)
else
respond_to do |format|
format.html { render(:new, flash: { error: @stamp_rally_check_in.errors.messages }) }
@stamp_rally_check_in = StampRallyCheckIn.new({ stamp_rally_check_point_id: params[:stamp_rally_check_point_id], profile: @profile, check_in_timestamp: Time.zone.now })

if @stamp_rally_check_in.save
redirect_to(stamp_rally_check_ins_path, flash: { notice: @stamp_rally_check_point.name.to_s })
else
respond_to do |format|
format.html { render(:new, flash: { error: @stamp_rally_check_in.errors.messages }) }
end
end
end
end
Expand Down

0 comments on commit 963e70d

Please sign in to comment.