From 4d5bb42331dd0f215b9c88ecea5551a93c3761cd Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Sun, 29 Mar 2020 16:19:22 +0300 Subject: [PATCH] Surveys: Grooming of messages to user --- app/controllers/surveys_controller.rb | 19 ++++++++++++++----- app/views/surveys/show.html.haml | 5 +++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/controllers/surveys_controller.rb b/app/controllers/surveys_controller.rb index 349bc34ba5..23f9964178 100644 --- a/app/controllers/surveys_controller.rb +++ b/app/controllers/surveys_controller.rb @@ -16,7 +16,7 @@ def show def reply unless can? :reply, @survey - redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is currently closed' + redirect_to conference_survey_path(@conference, @survey), alert: 'This survey is not available' return end @@ -33,13 +33,22 @@ def reply end user_survey_submission = @survey.survey_submissions.find_by(user: current_user) - if user_survey_submission - user_survey_submission.update_attributes(updated_at: Time.current) - else - @survey.survey_submissions.create!(user: current_user) + begin + if user_survey_submission + user_survey_submission.update_attributes(updated_at: Time.current) + else + @survey.survey_submissions.create!(user: current_user) + end + rescue => error + Rails.logger.info "Could not save submission reply for user #{current_user.email} with error: #{error.message}" + flash[:error] = "Something went wrong, please try again!" end end + unless flash[:error] + flash[:success] = 'Thank you for your submission!' + end + redirect_back(fallback_location: root_path) end end diff --git a/app/views/surveys/show.html.haml b/app/views/surveys/show.html.haml index 2efe7a651a..f97cc8782c 100644 --- a/app/views/surveys/show.html.haml +++ b/app/views/surveys/show.html.haml @@ -26,3 +26,8 @@ .row .col-md-10.col-md-offset-1 = f.submit 'Submit', class: 'btn btn-primary pull-right', disabled: !(can? :reply, @survey) + .pull-left + - if @survey.during_registration? + = link_to 'Back to Registration', conference_conference_registration_path(@conference) + - elsif @survey.after_event? + = link_to 'Back', conference_program_proposal_path(@conference, @survey.surveyable)