Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h1> My Portfolio</h1>
- <h3>Search for stocks</h3>
- <div id="stock-lookup">
- <%= form_tag search_stocks_path, remote: true, method: :get, id: "stock-lookup-form" do %>
- <div class="form-group row no-padding center col-md-12">
- <div class="col-md-10">
- <%= text_field_tag :stock, params[:stock], placeholder: "Stock ticker symbol", autofocus: true,
- class: "form-control search-box input-lg" %>
- </div>
- <div class="col-md-2">
- <%= button_tag :submit, class: "btn btn-lg btn-success" do %>
- <%= fa_icon "search" %> Look up a stock
- <% end %>
- </div>
- </div>
- <% end %>
- </div>
- <div id="results">
- <%= render 'users/result' %>
- </div>
- <% if @stock %>
- <div class="well results-block">
- <strong>Symbol: </strong><%= @stock.ticker %>
- <strong>Name: </strong><%=@stock.name %>
- <strong>Price: </strong><%= @stock.last_price %>
- </div>
- <% end %>
- class StocksController < ApplicationController
- def search
- if params[:stock].present?
- @stock = Stock.new_from_lookup(params[:stock])
- if @stock
- respond_to do |format|
- format.js { render partial: 'users/result' }
- end
- else
- flash[:danger] = "You have entered an invalid symbol."
- redirect_to my_portfolio_path
- end
- else
- flash[:danger] = "You have input an unexistant stock."
- redirect_to my_portfolio_path
- end
- end
- end
- <div class="well results-block">
- <strong>Symbol: </strong>GOOG
- <strong>Name: </strong>Alphabet Inc.
- <strong>Price: </strong>1042.1
- </div>
- $('#results').html("<%= j (render 'users/result') %>")
Add Comment
Please, Sign In to add comment