Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surveys: Grooming of messages to user #2651

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions app/controllers/surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, how can this happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cannot create the submission record (when create! raises an exception)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but I don't see any condition when this will happen? Only when the user already has submitted. Isn't all of this just some for of find_or_create_by?

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
5 changes: 5 additions & 0 deletions app/views/surveys/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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)