diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/alerts_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/games_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/main_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/static_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 32 |
6 files changed, 23 insertions, 24 deletions
diff --git a/app/controllers/alerts_controller.rb b/app/controllers/alerts_controller.rb index 333022a..6ab3663 100644 --- a/app/controllers/alerts_controller.rb +++ b/app/controllers/alerts_controller.rb @@ -23,7 +23,7 @@ class AlertsController < ApplicationController # POST /alerts.json def create @alert = Alert.new(alert_params) - + @alert.author = current_user respond_to do |format| if @alert.save format.html { redirect_to @alert, notice: 'Alert was successfully created.' } diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1f0bdd8..aec5294 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -67,6 +67,6 @@ class GamesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def game_params - params.require(:game).permit(:name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) + params.require(:game).permit(:parent_id, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) end end diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 6519d7b..0ba4d94 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,2 +1,4 @@ class MainController < ApplicationController + def homepage + end end diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb deleted file mode 100644 index 038cc19..0000000 --- a/app/controllers/static_controller.rb +++ /dev/null @@ -1,7 +0,0 @@ -class StaticController < ApplicationController - def homepage - end - - def test - end -end diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index b276368..0390051 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -33,7 +33,7 @@ class TournamentsController < ApplicationController def new @games = Game.all if params[:tournament] - @tournament = Tournament.new(game: Game.find(params[:tournament][:game_id])) + @tournament = Tournament.new(tournament_params) else @tournament = Tournament.new() end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index cfa5d67..4c36148 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -56,8 +56,25 @@ class UsersController < ApplicationController # PATCH/PUT /users/1 # PATCH/PUT /users/1.json def update + ok = true + if params[:user][:remote_usernames].nil? + ok &= @user.update(user_params) + else + params[:user][:remote_usernames].each do |game_name,user_name| + game = Game.find_by_name(game_name) + remote_username = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{user_name}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") + + remote = @user.remote_usernames.where(:game => game).first + if remote.nil? + ok &= @user.remote_usernames.create(game: game, value: remote_username) + else + remote.value = remote_username + ok &= remote.save + end + end + end respond_to do |format| - if @user.update(user_params) + if ok format.html { redirect_to @user, notice: 'User was successfully updated.' } format.json { head :no_content } else @@ -77,19 +94,6 @@ class UsersController < ApplicationController end end - def set_remote - game = Game.find_by_name("League of Legends") - - remote_username = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@name.downcase}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - remote = @user.find_remote_username(game) - if remote.nil? - @user.remote_username.create(game: game, value: remote_username) - else - remote.value = remote_username - remote.save - end - end private # Use callbacks to share common setup or constraints between actions. |