class StocksController < ApplicationController
  def search
    symbol = params[:stock]

    if symbol.present?
      @stock = Stock.new_lookup symbol

      if @stock
        respond_to do |format|
          format.js { render partial: 'users/result' }
        end
      else
        respond_to do |format|
          flash.now[:alert] = "Unknown stock symbol: #{symbol}"
          format.js { render partial: 'users/result' }
        end
      end
    else
      respond_to do |format|
        flash.now[:alert] = 'Please enter a symbol to search'
        format.js { render partial: 'users/result' }
      end
    end
  end
end
