Guest User

Untitled

a guest
Dec 14th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. <h1> My Portfolio</h1>
  2.  
  3. <h3>Search for stocks</h3>
  4. <div id="stock-lookup">
  5. <%= form_tag search_stocks_path, remote: true, method: :get, id: "stock-lookup-form" do %>
  6. <div class="form-group row no-padding center col-md-12">
  7. <div class="col-md-10">
  8. <%= text_field_tag :stock, params[:stock], placeholder: "Stock ticker symbol", autofocus: true,
  9. class: "form-control search-box input-lg" %>
  10. </div>
  11. <div class="col-md-2">
  12. <%= button_tag :submit, class: "btn btn-lg btn-success" do %>
  13. <%= fa_icon "search" %> Look up a stock
  14.  
  15. <% end %>
  16. </div>
  17.  
  18.  
  19. </div>
  20. <% end %>
  21.  
  22. </div>
  23. <div id="results">
  24. <%= render 'users/result' %>
  25. </div>
  26.  
  27. <% if @stock %>
  28. <div class="well results-block">
  29. <strong>Symbol: </strong><%= @stock.ticker %>
  30. <strong>Name: </strong><%=@stock.name %>
  31. <strong>Price: </strong><%= @stock.last_price %>
  32. </div>
  33. <% end %>
  34.  
  35. class StocksController < ApplicationController
  36. def search
  37.  
  38. if params[:stock].present?
  39. @stock = Stock.new_from_lookup(params[:stock])
  40. if @stock
  41. respond_to do |format|
  42. format.js { render partial: 'users/result' }
  43. end
  44. else
  45. flash[:danger] = "You have entered an invalid symbol."
  46. redirect_to my_portfolio_path
  47. end
  48.  
  49. else
  50. flash[:danger] = "You have input an unexistant stock."
  51. redirect_to my_portfolio_path
  52. end
  53.  
  54. end
  55. end
  56.  
  57. <div class="well results-block">
  58. <strong>Symbol: </strong>GOOG
  59. <strong>Name: </strong>Alphabet Inc.
  60. <strong>Price: </strong>1042.1
  61. </div>
  62.  
  63. $('#results').html("<%= j (render 'users/result') %>")
Add Comment
Please, Sign In to add comment