Class: CatalogController

Inherits:
ApplicationController show all
Defined in:
app/controllers/catalog_controller.rb

Direct Known Subclasses

Catalog::BrowserController, Catalog::IndexController

Instance Method Summary (collapse)

Instance Method Details

- (Object) show



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/catalog_controller.rb', line 4

def show
  if params['commit'] == 'Clear'
    @search_params = {}
    params['q'] = params['search_type'] = nil
    return
  end

  params['q'].strip! if params['q']

  @search_params = {'search_type' => params['search_type'], 'q' => params['q']}

  if @search_params['q'].present?
    params['id'] = nil if params[:is_search_form].present?
    @search_results = Taxon.find_name @search_params['q'], @search_params['search_type']
    unless @search_results.present?
      @search_results_message = "No results found"
    else
      @search_results = @search_results.map do |search_result|
        {name: search_result.full_label, id: search_result.id}
      end
      params['id'] = @search_results.first[:id] if params['id'].blank?
    end
  end
end