Module: Models::SearchAddressable

Extended by:
ActiveSupport::Concern
Included in:
ActivitySearch, CertificationSearch, ContactSearch, CustomerSearch, DeliverySearch, InvoiceSearch, LocatorRecordSearch, OrderSearch, QuoteSearch
Defined in:
app/concerns/models/search_addressable.rb

Overview

This concern is used for search views that have an address_id_field definition and allowing classic
address based geomap / googlemap

Instance Method Summary collapse

Instance Method Details

#mass_googlemap(params, _cur_user_id = 1) ⇒ Hash

Maps the current search results onto a Google map using the address field
named in the params.

Parameters:

  • params (Hash)

    action params; must include +:address_id_field_name+,
    the name of the resource method that returns the target address id

  • _cur_user_id (Integer) (defaults to: 1)

    unused, kept for mass-action interface parity

Returns:

  • (Hash)

    +:status :error+ with a +:message+ when no address field is
    given, otherwise +:status :ok+ with the collected address ids in
    +:result_data+



18
19
20
21
22
23
# File 'app/concerns/models/search_addressable.rb', line 18

def mass_googlemap(params, _cur_user_id = 1)
  return { status: :error, message: 'A target address must be specified.' } if params[:address_id_field_name].blank?

  ids = search_results.map { |sr| sr.resource.send(params[:address_id_field_name].to_sym) }
  { status: :ok, result_action: 'googlemap', result_data: ids }
end