Module: SearchWithGlobalize

Defined in:
lib/acts_as_page/search_with_globalize.rb

Instance Method Summary collapse

Instance Method Details

#with_globalize(conditions = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/acts_as_page/search_with_globalize.rb', line 3

def with_globalize(conditions = {})
  conditions = {locale: ::Globalize.locale.to_s}.merge(conditions)
  globalized_conditions = {}
  conditions.keys.each do |key|
    if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
      globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key)
    end
  end
  joins(:translations).where(globalized_conditions).where(conditions).readonly(false)
end