From 436adde70613bd19f5c8f1a053ac7d8d4a70630b Mon Sep 17 00:00:00 2001 From: Thor77 Date: Tue, 7 May 2019 15:33:21 +0200 Subject: [PATCH] Set global match var for reuse by other methods --- app/controllers/matches_controller.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index d15e841..549f4d7 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -1,8 +1,16 @@ # frozen_string_literal: true class MatchesController < ApplicationController + before_action :set_match, only: %i[show update] + # GET /matches/1 def show - render json: Match.find(params[:id]), include: ['match_scores.points', 'match_scores.team'] + render json: @match, include: ['match_scores.points', 'match_scores.team'] + end + + private + + def set_match + @match = Match.find(params[:id]) end end