def association(association, options = {}, &block)
      options = options.dup

      return simple_fields_for(*[association,
        options.delete(:collection), options].compact, &block) if block_given?

      raise ArgumentError, "Association cannot be used in forms not associated with an object" unless @object

      reflection = find_association_reflection(association)
      raise "Association #{association.inspect} not found" unless reflection

      options[:as] ||= :select
      options[:collection] ||= fetch_association_collection(reflection, options)

      attribute = build_association_attribute(reflection, association, options)

      input(attribute, options.merge(reflection: reflection))
    end
def association(association, options = {}, &block)
      options = options.dup

      return simple_fields_for(*[association,
        options.delete(:collection), options].compact, &block) if block_given?

      raise ArgumentError, "Association cannot be used in forms not associated with an object" unless @object

      reflection = find_association_reflection(association)
      raise "Association #{association.inspect} not found" unless reflection

      options[:as] ||= :select
      options[:collection] ||= fetch_association_collection(reflection, options)

      attribute = build_association_attribute(reflection, association, options)

      input(attribute, options.merge(reflection: reflection))
    end
Helper for dealing with association selects/radios, generating the
 collection automatically. It's just a wrapper to input, so all options
 supported in input are also supported by association. Some extra options
 can also be given:

 == Examples

   simple_form_for @user do |f|
     f.association :company          # Company.all
   end

   f.association :company, collection: Company.all(order: 'name')
   # Same as using :order option, but overriding collection

 == Block

 When a block is given, association simple behaves as a proxy to
 simple_fields_for:

   f.association :company do |c|
     c.input :name
     c.input :type
   end

 From the options above, only :collection can also be supplied.

 Please note that the association helper is currently only tested with Active Record. Depending on the ORM you are using your mileage may vary.