Module: SearchableHelper

Defined in:
app/helpers/searchable_helper.rb

Overview

A collection of helper methods used to search resources with Ransack.

Instance Method Summary collapse

Instance Method Details

#search_form(q:, model:, url: url_for(model)) ⇒ Object

Renders a form with a field to search within model that uses placeholder.

Parameters:

  • q (String)

    the search query.

  • model (ApplicationRecord)

    the model of each object returned by the search



6
7
8
9
10
# File 'app/helpers/searchable_helper.rb', line 6

def search_form(q:, model:, url: url_for(model))
  search_form_for(q, search_form_params(url: url)) do |form|
    safe_join [filter_field_for(form, model:), search_field_for(form, model:)].compact
  end
end

#search_highlight(content, model:) ⇒ Object

Highlights the search query within the text of the matched content.



13
14
15
# File 'app/helpers/searchable_helper.rb', line 13

def search_highlight(content, model:)
  highlight content.to_s, params.dig(:q, model.search_field)
end