Class: SirTrevorRails::Blocks::SearchResultsBlock

Inherits:
SirTrevorRails::Block show all
Includes:
Displayable
Defined in:
app/models/sir_trevor_rails/blocks/search_results_block.rb

Overview

Embed search results (from a browse category) into the page

Constant Summary

Constants inherited from SirTrevorRails::Block

SirTrevorRails::Block::DEFAULT_FORMAT

Instance Attribute Summary

Attributes inherited from SirTrevorRails::Block

#parent, #type

Instance Method Summary collapse

Methods included from Displayable

#item_ids, #items, #ordered_items

Methods inherited from SirTrevorRails::Block

#alt_text?, alt_text?, #as_json, block_class, block_class!, custom_block_type_alt_text_settings, custom_block_types, #format, from_hash, #initialize, #to_partial_path, type_klass

Constructor Details

This class inherits a constructor from SirTrevorRails::Block

Instance Method Details

#query_paramsObject



10
11
12
13
14
15
16
# File 'app/models/sir_trevor_rails/blocks/search_results_block.rb', line 10

def query_params
  if search
    search.query_params
  else
    {}
  end
end

#searchObject



18
19
20
# File 'app/models/sir_trevor_rails/blocks/search_results_block.rb', line 18

def search
  searches.first
end

#searchesObject



22
23
24
# File 'app/models/sir_trevor_rails/blocks/search_results_block.rb', line 22

def searches
  @searches ||= parent.exhibit.searches.published.where(slug: item_ids).sort { |a, b| ordered_items.index(a.id) <=> ordered_items.index(b.id) }
end

#searches?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/sir_trevor_rails/blocks/search_results_block.rb', line 26

def searches?
  !searches.empty?
end