summaryrefslogtreecommitdiff
path: root/app/controllers
diff options
context:
space:
mode:
authorguntasgrewal <guntasgrewal@gmail.com>2014-04-23 22:50:48 -0400
committerguntasgrewal <guntasgrewal@gmail.com>2014-04-23 22:50:48 -0400
commit41a93fad32677e3f351c0e16f0c704cbfbc5404e (patch)
treeaa46c550dbd15a1f0bb0faf4e8eebb92c4970bdd /app/controllers
parent19b04a49d01af1917385c166501ef086eddae437 (diff)
parent47be7c86ca5193ffe4331fbb9358a9171abe748b (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/games_controller.rb2
-rw-r--r--app/controllers/main_controller.rb2
-rw-r--r--app/controllers/static_controller.rb7
-rw-r--r--app/controllers/tournaments_controller.rb2
-rw-r--r--app/controllers/users_controller.rb32
5 files changed, 22 insertions, 23 deletions
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.