I'm working on a little stock market app where the users can lookup company stock info based on the ticker symbol. After the user has posted the :symbol param in the search field, they should be redirected to the appropriate "company" page (like Wall Street Journal, Yahoo Finance, Google Finance, etc). I'm currently able to manually type in the route with the symbol and everything works good. For example, localhost:9292/company/GOOG. I'm a total noob, so any help would be greatly appreciated. Thanks!
I currently have this in my view:
<%== search_field_tag(:symbol, "Enter symbol") %>
<%== submit_tag ("Search") %>
This is in my routes:
get "/company/:symbol" => "main#company"
post "/company/:symbol" => "main#company_post"
EDIT: I'm using the MarketBeat gem to pull in the data, but I also have a Company table where I have columns symbol and name. Here is my controller:
class MainController < ApplicationController
def index
render :index and return
end
def company
@name = MarketBeat.company params["symbol"]
@symbol = MarketBeat.symbol params["symbol"]
@price = MarketBeat.last_trade_real_time params["symbol"]
@change = MarketBeat.change_and_percent_change params["symbol"]
@volume = MarketBeat.volume params["symbol"]
@days_range = MarketBeat.days_range params["symbol"]
@eps = MarketBeat.earnings_to_share params["symbol"]
@pe = MarketBeat.pe_ratio params["symbol"]
@stock_exchange = MarketBeat.stock_exchange params["symbol"]
market_cap = MarketBeat.market_capitalization params["symbol"]
# @market_cap is rounded to billions
@market_cap = market_cap.to_i / 1000
render :company and return
end