Created
August 29, 2012 23:03
-
-
Save JFickel/3520055 to your computer and use it in GitHub Desktop.
OpenURI::HTTPError in UsersController#update: app/controllers/users_controller.rb:43:in `block in update', app/controllers/users_controller.rb:26:in `update'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UsersController < ApplicationController | |
def new | |
@user = User.new | |
end | |
def create | |
@user = User.new(params[:user]) | |
if @user.save | |
flash[:notice] = "Thanks for signing up. Important! In order to have full functionality of the site, add your game accounts to your profile." | |
session[:user_id] = @user.id | |
redirect_to edit_user_path(@user) | |
else | |
flash[:notice] = "Didn't work" | |
redirect_to signup_path | |
end | |
end | |
def edit | |
@user = User.find(session[:user_id]) | |
end | |
def update | |
@user = User.find(params[:id]) | |
respond_to do |format| | |
if @user.update_attributes(params[:user]) | |
if @user.sc2_url? | |
if @user.sc2_url[7,2] == 'us' | |
@user.sc2_server = "US" | |
end | |
if @user.sc2_url[7,2] == 'eu' | |
@user.sc2_server = "EU" | |
end | |
if @user.sc2_url[7,2] == 'kr' | |
@user.sc2_server = "KOR" | |
end | |
@user.sc2_character = @user.sc2_url.split('/').last | |
@user.sc2_identifier = @user.sc2_url.split('/')[6] | |
@sc2_profile_doc = Nokogiri::HTML(open(@user.sc2_url)) | |
@user.sc2_league = @sc2_profile_doc.xpath('//*[(@id = "career-stats")]//*[(((count(preceding-sibling::*) + 1) = 1) and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "league-name", " " ))]').text | |
@sc2_ladder_doc = Nokogiri::HTML(open("http://us.battle.net/sc2/en/profile/#{@sc2_identifier}/1/#{@sc2_character}/ladder/leagues#current-rank")) | |
@user.sc2_points = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 4) and parent::*)][@class = "align-center"]').text | |
@user.sc2_wins = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 5) and parent::*)]').text | |
@user.sc2_losses = @sc2_ladder_doc.xpath('//*[(@id = "current-rank")]//*[(((count(preceding-sibling::*) + 1) = 6) and parent::*)]').text | |
end | |
if @user.lol_summoner_name? | |
@lol_na_doc = Nokogiri::HTML(open("http://competitive.na.leagueoflegends.com/ladders/na/current/rankedsolo5x5?summoner_name=#{@user.lol_summoner_name}")) | |
@user.lol_rank = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-rank", " " ))]').text | |
@user.lol_wins = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-wins", " " ))]').text | |
@user.lol_losses = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-losses", " " ))]').text | |
@user.lol_rating = @lol_na_doc.xpath('//*[contains(concat( " ", @class, " " ), concat( " ", "views-field-rating", " " ))]').text | |
end | |
@user.save | |
format.html { redirect_to @user, notice: 'User was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: "edit" } | |
format.json { render json: @user.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
def index | |
end | |
def show | |
if logged_in? | |
if !User.find(session[:user_id]).nil? | |
@user = User.find(session[:user_id]) | |
else | |
redirect_to welcome_path | |
end | |
else | |
redirect_to welcome_path | |
end | |
if @user.battle_tag? | |
@d3_profile = ActiveSupport::JSON.decode(open("http://us.battle.net/api/d3/profile/#{@user.battle_tag}-#{@user.battle_tag_id}/").read) | |
@array_of_hero_names = [] | |
@d3_profile['heroes'].each do |hero| | |
@array_of_hero_names << hero ["name"] | |
end | |
@d3_kills = @d3_profile['kills'] | |
end | |
if @user.sc2_url? | |
if @user.sc2_url[7,2] == 'us' | |
@sc2_country_icon = 'sc2-icon-us.png' | |
end | |
if @user.sc2_url[7,2] == 'eu' | |
@sc2_country_icon = 'sc2-icon-eu.png' | |
end | |
if @user.sc2_url[7,2] == 'kr' | |
@sc2_country_icon = 'sc2-icon-kor.png' | |
end | |
end | |
# sc2ranks = SC2Ranks::API.new | |
# @sc2_character = sc2ranks.get_character("HuK", 530) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment