From 96a663f08f30bd1e873edbca19840723501b7c86 Mon Sep 17 00:00:00 2001 From: oleghasjanov Date: Wed, 14 Aug 2024 12:08:43 +0300 Subject: [PATCH] added logs for offer actions --- app/controllers/english_offers_controller.rb | 29 ++++++++++++-------- app/controllers/offers_controller.rb | 10 +++++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/app/controllers/english_offers_controller.rb b/app/controllers/english_offers_controller.rb index 0e17a2cbf..1a20a0f1f 100644 --- a/app/controllers/english_offers_controller.rb +++ b/app/controllers/english_offers_controller.rb @@ -35,13 +35,15 @@ def create broadcast_update_auction_offer(@auction) send_outbided_notification(auction: @auction, offer: @offer, flash:) update_auction_values(@auction, t('english_offers.create.created')) + Rails.logger.info("User #{current_user.id} created offer #{@offer.id} for auction #{@auction.id}") else - flash[:alert] = if @offer.errors.full_messages_for(:cents).present? - @offer.errors.full_messages_for(:cents).join - else - @offer.errors.full_messages.join('; ') - end - + errors = if @offer.errors.full_messages_for(:cents).present? + @offer.errors.full_messages_for(:cents).join + else + @offer.errors.full_messages.join('; ') + end + flash[:alert] = errors + Rails.logger.error("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{errors}") redirect_to root_path and return end end @@ -67,13 +69,16 @@ def update broadcast_update_auction_offer(@auction) send_outbided_notification(auction: @auction, offer: @offer, flash:) update_auction_values(@auction, t('english_offers.edit.bid_updated')) + Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{@auction.id}") else - flash[:alert] = if @offer.errors.full_messages_for(:cents).present? - @offer.errors.full_messages_for(:cents).join - else - @offer.errors.full_messages.join('; ') - end - + errors = if @offer.errors.full_messages_for(:cents).present? + @offer.errors.full_messages_for(:cents).join + else + @offer.errors.full_messages.join('; ') + end + + flash[:alert] = errors + Rails.logger.error("User #{current_user.id} tried to update offer for auction #{offer.auction.id} but it failed. Errors: #{errors}") redirect_to root_path end end diff --git a/app/controllers/offers_controller.rb b/app/controllers/offers_controller.rb index f6b4245f1..415ba7711 100644 --- a/app/controllers/offers_controller.rb +++ b/app/controllers/offers_controller.rb @@ -29,10 +29,13 @@ def create redirect_to root_path, notice: t('offers.already_exists') end elsif create_predicate + Rails.logger.info("User #{current_user.id} created offer #{@offer.id} for auction #{@auction.id}") format.html { redirect_to root_path, notice: t('.created') } format.json { render :show, status: :created, location: @offer } else - flash[:alert] = @offer.errors.full_messages.join('; ') + error_msg = @offer.errors.full_messages.join('; ') + flash[:alert] = error_msg + Rails.logger.error("User #{current_user.id} tried to create offer for auction #{@auction.id} but it failed. Errors: #{error_msg}") format.html { redirect_to root_path, status: :see_other } format.json { render json: @offer.errors, status: :unprocessable_entity } end @@ -63,10 +66,13 @@ def update redirect_to root_path and return if update_not_allowed(@offer.auction) if update_predicate + Rails.logger.info("User #{current_user.id} updated offer #{@offer.id} for auction #{@offer.auction.id}") format.html { redirect_to root_path, notice: t(:updated), status: :see_other } format.json { render :show, status: :ok, location: @offer } else - flash[:alert] = @offer.errors.full_messages.join('; ') + errors = @offer.errors.full_messages.join('; ') + flash[:alert] = errors + Rails.logger.error("User #{current_user.id} tried to update offer for auction #{offer.auction.id} but it failed. Errors: #{errors}") format.html { redirect_to root_path, status: :see_other } format.json { render json: @offer.errors, status: :unprocessable_entity } end