user3277633
user3277633

Reputation: 1923

Incorporate ruby parameters into string raises bad url error

Not sure what I'm doing here

def get_full_stats(id)
        riot_url = 'https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/#{id}/ranked?api_key=mykey'
        response = HTTParty.get(riot_url)
        json = JSON.parse(response.body)
        json
    end

and in my show.html.erb I am calling the following

api = RiotApi.new
@info = api.get_full_stats(19380406)

the view is returning to me wrong number of arguments (1 for 0) for the @info = api.get_full_stats(19380406) line.

I tried casting the parameter as a string @info = api.get_full_stats('19380406') but still raises the same error.

What's going on here?

After restarting the server, it appears that I now have a URI::InvalidURIError Error instead.

Upvotes: 2

Views: 49

Answers (1)

user1002119
user1002119

Reputation: 3812

You need to use double quotes for string interpolation to work. For example,

def get_full_stats(id)
    riot_url = "https://na.api.pvp.net/api/lol/na/v1.3/stats/by-summoner/#{id}/ranked?api_key=mykey"
    response = HTTParty.get(riot_url)
    json = JSON.parse(response.body)
    json
end

Upvotes: 2

Related Questions