Sha256: bac74f2904fa3663cbe82682a8dadae2a3b616b8c164419e1ff24543aeae6175

Contents?: true

Size: 819 Bytes

Versions: 18

Compression:

Stored size: 819 Bytes

Contents

module DynamicScaffold
  module Form
    module Item
      class Cocoon < Base
        attr_reader :form
        def initialize(config, type, name, options = {})
          super
          @options = options
          @form = FormBuilder.new(config)
          yield(@form)
        end

        def extract_parameters(permitting)
          permitting << { "#{@name}_attributes": [*@form.items.map(&:name).push(:_destroy)] }
        end

        def filter(&block)
          @filter = block
          self
        end

        def add_text
          @options[:add_text] || "Add #{proxy_field.label}"
        end

        def build_children(record)
          children = record.public_send(name).to_a
          children = @filter.call(children) if @filter.present?
          children
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
dynamic_scaffold-1.7.1 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.7.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.6.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.5.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.4.3 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.4.2 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.4.1 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.4.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.3.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.2.2 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.2.1 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.2.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.1.4 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.1.3 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.1.2 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.1.1 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.1.0 lib/dynamic_scaffold/form/item/cocoon.rb
dynamic_scaffold-1.0.0 lib/dynamic_scaffold/form/item/cocoon.rb