Check whether a key exists correctly

This commit is contained in:
Daniel Schädler 2019-04-11 15:09:32 +02:00
parent f223c03686
commit f2dfb123e0
1 changed files with 2 additions and 2 deletions

View File

@ -23,9 +23,9 @@ class TournamentsController < ApplicationController
params.require(:teams) params.require(:teams)
# convert teams parameter into Team objects # convert teams parameter into Team objects
teams = params.delete('teams').map do |team| teams = params.delete('teams').map do |team|
if team[:id] if team.key? 'id'
Team.find team[:id] Team.find team[:id]
elsif team[:name] elsif team.key? 'name'
Team.create name: team[:name] Team.create name: team[:name]
end end
end end