I am trying to display the results of an external API when the user types in the ticker on the new stock form. What I am trying to accomplish is kind of stock search engine using the stock quote gem, so when the user types in the ticker it'll display some data points on that page and if the user hits submit it'll store that ticker and the price in the DB.
Here is my controller
def new
@assignment = Assignment.new(portfolio_id: params[:portfolio_id])
@stock = Assignment.new_from_lookup(params[:ticker])
end
And my model
def self.new_from_lookup(symbol)
begin
stock = StockQuote::Stock.quote(symbol)
new(company_name: stock.company_name,
symbol: stock.symbol,
latest_price: stock.latest_price,
latest_time: stock.latest_time)
rescue Exception => e
# Rescues all errors, an puts the exception object in `e
return nil
end
end
I hope this isn't too broad of a question but how would I display the data points on the form when the ticker is entered and store the data points if the submit button is clicked?