RapidAPI:"FB":String 的未定义方法“get_company”
RapidAPI: undefined method `get_company' for "FB":String
我正尝试在我的 Rails 应用程序中通过 RapidAPI 从 IEX Trading API 提取数据。我已经创建了一个搜索表单,其中查询将用于获取数据,但是即使它在控制台中工作正常(在本例中查询为 "FB"),也会出现以下错误消息:
未定义方法 'get_company' for "FB":String
stock.rb
class Stock < ApplicationRecord
validates :ticker, uniqueness: true
def self.get_company
response = Unirest.get "https://investors-exchange-iex-trading.p.rapidapi.com/stock/#{@stock}/company",
headers: {
"X-RapidAPI-Key" => [xxx]
}
company = response.body
@stock = Stock.create(
ticker: company["symbol"],
name: company["companyName"],
exchange: company["Exchange"],
sector: company["industry"],
website: company["website"],
description: company["description"]
)
end
end
stocks_controller.rb
class StocksController < ApplicationController
def search
end
def result
@stock = params[:stock]
@stock.get_company unless @stock.nil?
end
end
非常感谢!
尝试
def result
@stock = params[:stock]
Stock.get_company(@stock) unless @stock.nil? end
def self.get_company(stock)
@stock = stock
response = Unirest.get "https://investors-exchange-iex-trading.p.rapidapi.com/stock/#{@stock}/company", headers: { "X-RapidAPI-Key" => [xxx] }
我正尝试在我的 Rails 应用程序中通过 RapidAPI 从 IEX Trading API 提取数据。我已经创建了一个搜索表单,其中查询将用于获取数据,但是即使它在控制台中工作正常(在本例中查询为 "FB"),也会出现以下错误消息:
未定义方法 'get_company' for "FB":String
stock.rb
class Stock < ApplicationRecord
validates :ticker, uniqueness: true
def self.get_company
response = Unirest.get "https://investors-exchange-iex-trading.p.rapidapi.com/stock/#{@stock}/company",
headers: {
"X-RapidAPI-Key" => [xxx]
}
company = response.body
@stock = Stock.create(
ticker: company["symbol"],
name: company["companyName"],
exchange: company["Exchange"],
sector: company["industry"],
website: company["website"],
description: company["description"]
)
end
end
stocks_controller.rb
class StocksController < ApplicationController
def search
end
def result
@stock = params[:stock]
@stock.get_company unless @stock.nil?
end
end
非常感谢!
尝试
def result
@stock = params[:stock]
Stock.get_company(@stock) unless @stock.nil? end
def self.get_company(stock)
@stock = stock
response = Unirest.get "https://investors-exchange-iex-trading.p.rapidapi.com/stock/#{@stock}/company", headers: { "X-RapidAPI-Key" => [xxx] }