Sha256: 865f2eeeebed6e31b61313ab76c8906324c3dd2615d05893e228458dc147ab70

Contents?: true

Size: 1018 Bytes

Versions: 6

Compression:

Stored size: 1018 Bytes

Contents

ActionView::Helpers::FormHelper.class_eval do
  private

  alias_method :old_apply_form_for_options!, :apply_form_for_options!
  def apply_form_for_options!(record, object, options) #:nodoc:
    if record.is_a?(RecordCollection::Base)
        object = convert_to_model(object)

        as = options[:as]
        namespace = options[:namespace]
        action, method = [:collection_update, :post]
        options[:html].reverse_merge!(
          class:  as ? "#{action}_#{as}" : dom_class(object, action),
          id:     (as ? [namespace, action, as] : [namespace, dom_id(object, action)]).compact.join("_").presence,
          method: method
        )

        options[:url] ||= if options.key?(:format)
                            polymorphic_path([action, record], format: options.delete(:format))
                          else
                            polymorphic_path([action, record], {})
                          end
    else
      old_apply_form_for_options!(record, object, options)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
record_collection-0.9.2 lib/record_collection/rails/form_helper.rb
record_collection-0.9.1 lib/record_collection/rails/form_helper.rb
record_collection-0.9.0 lib/record_collection/rails/form_helper.rb
record_collection-0.8.3 lib/record_collection/rails/form_helper.rb
record_collection-0.8.2 lib/record_collection/rails/form_helper.rb
record_collection-0.8.1 lib/record_collection/rails/form_helper.rb