Sha256: af1a872329f08bd30efb197c3e61973c801ed06772b4eacdab0930943bab7f82

Contents?: true

Size: 663 Bytes

Versions: 20

Compression:

Stored size: 663 Bytes

Contents

require "active_support/concern"

module LookupBy
  module Hooks
    module Formtastic
      extend ActiveSupport::Concern

      included do
        alias_method_chain :input, :lookup
      end

      def input_with_lookup(method, options = {})
        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.cache_all?
        end

        input_without_lookup(method, options)
      end
    end
  end
end

::Formtastic::FormBuilder.send :include, LookupBy::Hooks::Formtastic

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
lookup_by-0.10.4 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.10.3 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.10.2 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.10.1 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.10.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.9.1 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.9.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.8.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.7.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.5.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.4.1 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.4.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.3.2 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.3.1 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.2.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.1.3 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.1.2 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.1.1 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.6.0 lib/lookup_by/hooks/formtastic.rb
lookup_by-0.1.0 lib/lookup_by/hooks/formtastic.rb