Skip to content

Commit

Permalink
Refactor stock search and add country code filter option
Browse files Browse the repository at this point in the history
  • Loading branch information
Shpigford committed Nov 20, 2024
1 parent dc3f476 commit c8fb28a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/controllers/stocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def index
end

if params[:combobox].present?
scope = Stock.order(:name).search(params[:q])
scope = Stock.order(:name)
scope = scope.where(country_code: params[:country_code]) if params[:country_code].present?
scope = scope.search(params[:q])
@pagy, @stocks = pagy(scope, limit: 27, size: [ 1, 3, 3, 1 ])
@total_stocks = @pagy.count
render :index, variants: [ :combobox ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Tool::Presenter::CompoundInterestCalculator < Tool::Presenter
attribute :initial_investment, :tool_float, default: 0.0
attribute :monthly_contribution, :tool_float, default: 0.0
attribute :years_to_grow, :tool_float, default: 0.0, min: 0.0, max: 150.0
attribute :filter, :string

def blank?
[ initial_investment, monthly_contribution, years_to_grow, annual_interest_rate ].all?(&:zero?)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_with method: :get, data: { controller: "insider-form" } do |form| %>
<div class="search-combobox">
<%= combobox_tag "symbol", stocks_path(combobox: true),
<%= combobox_tag "symbol", stocks_path(combobox: true, country_code: "US"),
label: "Company Symbol",
placeholder: "Search for a stock",
required: true,
Expand Down

0 comments on commit c8fb28a

Please sign in to comment.