以下代码有问题。我没有收到任何错误,但是由于某种原因,每当我使用在字符串中带有空格的搜索关键字时,我的结果就会变空。我已经尝试过使用urleescape,但这也行不通。有人有见识吗?
require 'httparty'
require 'uri'
class Recipe
include HTTParty
base_uri 'recipepuppy.com'
default_params onlyImages: "1"
format :json
#Uses request parameter to send to API
def self.for(q)
q = URI.escape(q)
p q
get("/api", query: {q: q})["results"]
end
end
puts Recipe.for "chocolate"
puts Recipe.for "apple pie"