Module: TalentScout::Helper

Defined in:
lib/talent_scout/helper.rb

Instance Method Summary collapse

Instance Method Details

Renders an anchor element that links to a specified search. The search is specified in the form of a ModelSearch search object, which is converted to URL query params. By default, the link will point to the current controller and current action, but this can be overridden by passing a search_options Hash in place of the search object (see method overloads).

Overloads:

  • #link_to_search(name, search, html_options = nil) ⇒ String

    Parameters:

    • name (String)

      link text

    • search (TalentScout::ModelSearch)

      search object

    • html_options (Hash, nil) (defaults to: nil)

      HTML options (see ActionView::Helpers::UrlHelper#link_to)

  • #link_to_search(search, html_options = nil, &block) ⇒ String

    Parameters:

    • search (TalentScout::ModelSearch)

      search object

    • html_options (Hash, nil) (defaults to: nil)

      HTML options (see ActionView::Helpers::UrlHelper#link_to)

    Yield Returns:

    • (String)

      link text

  • #link_to_search(name, search_options, html_options = nil) ⇒ String

    Parameters:

    • name (String)

      link text

    • search_options (Hash)

      search options

    • html_options (Hash, nil) (defaults to: nil)

      HTML options (see ActionView::Helpers::UrlHelper#link_to)

    Options Hash (search_options):

    • :search (TalentScout::ModelSearch)

      search object

    • :controller (String, nil)

      controller to link to (defaults to current controller)

    • :action (String, nil)

      controller action to link to (defaults to current action)

  • #link_to_search(search_options, html_options = nil, &block) ⇒ String

    Parameters:

    • search_options (Hash)

      search options

    • html_options (Hash, nil) (defaults to: nil)

      HTML options (see ActionView::Helpers::UrlHelper#link_to)

    Options Hash (search_options):

    • :search (TalentScout::ModelSearch)

      search object

    • :controller (String, nil)

      controller to link to (defaults to current controller)

    • :action (String, nil)

      controller action to link to (defaults to current action)

    Yield Returns:

    • (String)

      link text

Returns:

  • (String)

Raises:

  • (ArgumentError)

    if search or search_options[:search] is nil



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/talent_scout/helper.rb', line 58

def link_to_search(name, search = nil, html_options = nil, &block)
  name, search, html_options = nil, name, search if block_given?

  if search.is_a?(Hash)
    url_options = search.dup
    search = url_options.delete(:search)
  else
    url_options = {}
  end

  raise ArgumentError, "`search` cannot be nil" if search.nil?

  url_options[:controller] ||= controller_path
  url_options[:action] ||= action_name
  url_options[search.model_name.param_key] = search.to_query_params

  if block_given?
    link_to(url_options, html_options, &block)
  else
    link_to(name, url_options, html_options)
  end
end