LoginSignup
Nohem
@Nohem

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

rails(ruby)でのURL内の式展開

Q&AClosed

解決したいこと

rails(ruby)での式展開

例)
Ruby on RailsからAPIへのリクエストを送りたいと思います。
location_idを手打ちした場合は、レスポンスがあるのですが、
式展開した場合上手くいきません…

該当するソースコード

ソースコードを入力

例)

# @location_id = city.location_id
# url = "https://api.openweathermap.org/data/2.5/weather?id=#{@location_id}&appid=#{ENV['OPEN_WEATHER_API_KEY']}&units=metric"
url = "https://api.openweathermap.org/data/2.5/weather?id=6940394&appid=#{ENV['OPEN_WEATHER_API_KEY']}&units=metric"

コメントアウトしている部分がうまく動かず、3行目のように直接打つとレスポンスが得られます。

0

No Answers yet.

Your answer might help someone💌