Module: LookupBy::Hooks::SimpleForm

Extended by:
ActiveSupport::Concern
Defined in:
lib/lookup_by/hooks/simple_form.rb

Instance Method Summary collapse

Instance Method Details

#input_with_lookup(method, options = {}, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lookup_by/hooks/simple_form.rb', line 13

def input_with_lookup(method, options = {}, &block)
  klass = object.class

  if klass.respond_to?(:lookups) && klass.lookups.include?(method.to_sym)
    target = method.to_s.classify.constantize

    options[:collection] ||= target.pluck(target.lookup.field) if target.lookup.has_cache?
  end

  input_without_lookup(method, options, &block)
end