diff options
author | tkimia <tkimia@purdue.edu> | 2014-04-23 20:38:19 -0400 |
---|---|---|
committer | tkimia <tkimia@purdue.edu> | 2014-04-23 20:38:19 -0400 |
commit | 7ff82b901705475f97e277a9f3f31756bd3ce948 (patch) | |
tree | 9353d3b18477598eb9a7403541595dc0a750ec9a /app/controllers | |
parent | 190bfeb784f9760326c54069d2dbf875a820c6ec (diff) | |
parent | a729106e956e051818bb2d37f1581f3bf3abcefd (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/tournaments_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 17 |
2 files changed, 28 insertions, 2 deletions
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 03dc5b8..b276368 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -32,7 +32,11 @@ class TournamentsController < ApplicationController # GET /tournaments/new def new @games = Game.all - @tournament = Tournament.new(game: Game.find_by_id(params[:game])) + if params[:tournament] + @tournament = Tournament.new(game: Game.find(params[:tournament][:game_id])) + else + @tournament = Tournament.new() + end end # GET /tournaments/1/edit @@ -146,7 +150,12 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_params - params.require(:tournament).permit(:game, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method) + permitted = [:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method] + if params[:tournament][:game_id] + game = Game.find(params[:tournament][:game_id]) + permitted.push(:settings => game.settings.collect{|s| s.name}) + end + params.require(:tournament).permit(permitted) end def is_owner?(object) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c3261b8..cfa5d67 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,8 @@ class UsersController < ApplicationController + require 'httparty' + require 'json' + # GET /users # GET /users.json @@ -74,6 +77,20 @@ 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. def set_user |