im试图将包含.env文件中没有运气的api键的变量插入到url中。当我直接添加密钥时,代码可以正常工作,但是插值时会出现401未经授权的错误。不知道我在做什么错,谢谢
class TestsController < ApplicationController
require "open-uri"
def index
url = "https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=#{ENV['NEWS_API_KEY']}"
article_serialized = open(url).read
@articles = JSON.parse(article_serialized)
end
end
NEWS_API_KEY=************************