Skip to content

Commit

Permalink
Error when we can't save a judgement (#809)
Browse files Browse the repository at this point in the history
* in cases where we double create the same thing, be smarter...
  • Loading branch information
epugh authored Aug 31, 2023
1 parent 4e662f5 commit d862ee2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 59 deletions.
4 changes: 2 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class HomeController < ApplicationController
# rubocop:disable Metrics/AbcSize
def show
# @cases = @current_user.cases.not_archived.includes([ :scores ])
@cases = @current_user.cases.not_archived.recent.uniq
@cases = @current_user.cases.not_archived

@most_recent_cases = @cases[0...4].sort_by(&:case_name)
@most_recent_cases = @current_user.cases.not_archived.recent.limit(4).sort_by(&:case_name)

@most_recent_books = []
@lookup_for_books = {}
Expand Down
10 changes: 10 additions & 0 deletions app/controllers/judgements_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,19 @@ def create
@judgement.user = current_user
@judgement.unrateable = false

# Make sure that we haven't already created the same judgement before
# This create UI can happen very quickly, and somehow we get overlapping creates..
if !@judgement.valid? && (@judgement.errors.added? :user_id, :taken, value: @current_user.id)
@judgement = Judgement.find_by(user_id: @current_user.id, query_doc_pair_id: @judgement.query_doc_pair_id)
@judgement.update(judgement_params)
@judgement.user = current_user
@judgement.unrateable = false
end

if @judgement.save
redirect_to book_judge_path(@book)
else
@query_doc_pair = @judgement.query_doc_pair
render action: :new
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

<%= favicon_link_tag asset_path "favicon.ico" %>

<!-- Probably better way of doing this -->
<% if flash[:unfurl] %>
<!-- We have unfurl -->

Expand Down Expand Up @@ -33,7 +32,6 @@
<meta name="twitter:data1" value="<%=Case.find_by_id(flash[:unfurl]["id"]).tries.latest.try_number %>" />
<% end %>
<% else %>
<!-- We DO NOT have unfurl -->

<title>Quepid -- Relevant Search Solved</title>

Expand All @@ -60,7 +58,7 @@
<%= csrf_meta_tags %>
<%= javascript_include_tag 'application' %>

</head>
</head>

<body>

Expand Down
54 changes: 0 additions & 54 deletions test/controllers/judgements_controller_test.txt

This file was deleted.

0 comments on commit d862ee2

Please sign in to comment.