我在运行应用程序时似乎遇到错误:
getaddrinfo: Name or service not known
我认为错误是因为应用程序与使用服务检索api的服务器之间没有连接。我使用RestClient
gem来访问请求。
#services/get_games.rb
class GetGames
def self.get_games
response = RestClient::Request.execute(
method: :get,
url: 'https://api-2445582011268.apicast.io.json',
headers: {user_key: ENV["IGDB_API"], accept:'application/json'}
)
end
end
#games_controller
def index
@response = JSON.parse(GetGames.get_games)
@games = Game.all
end
答案 0 :(得分:1)
我认为如果您取消.json
中的url
,错误就会消失。