Skip to content
Merged
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
4 changes: 2 additions & 2 deletions app/controllers/v1/predictions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class V1::PredictionsController < ApplicationController
def create
@match = Match.find(params[:match_id])
@match = Match.upcoming.find(params[:match_id])
@prediction = Prediction.new(prediction_params)
@prediction.match = @match
@prediction.user = current_user
Expand All @@ -13,7 +13,7 @@ def create
end

def update
@prediction = Prediction.find_by(user: current_user, match: params[:match_id])
@prediction = Prediction.editable.find_by(user: current_user, match: params[:match_id])
authorize @prediction
if @prediction.update(prediction_params)
render :show
Expand Down
1 change: 1 addition & 0 deletions app/models/prediction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Prediction < ApplicationRecord
validates :choice, presence: true
enum choice: { home: 'home', away: 'away', draw: 'draw' }

scope :editable, -> { joins(:match).where(matches: { status: :upcoming }) }
scope :locked, -> { joins(:match).where.not(matches: { status: :upcoming }) }

after_commit :refresh_materialized_views
Expand Down