module LookupBy::Hooks::SimpleForm

Public Instance Methods

input_with_lookup(method, options = {}, &block) click to toggle source
# 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