Sha256: f07d9feef3160e36af463ed4a55abaed2e6374ed21496b11c4d97b6ae954afb4

Contents?: true

Size: 910 Bytes

Versions: 8

Compression:

Stored size: 910 Bytes

Contents

module DynamicScaffold
  class FormBuilder
    attr_accessor :parent_item

    def initialize(config)
      @config = config
      @items = []
      @permit_params = []
    end

    def items
      if @items.empty?
        @config.model.column_names.each do |column|
          type = :text_field
          type = :hidden_field if @config.scope && @config.scope.include?(column.to_sym)
          item = Form::Item::SingleOption.new(@config, type, column)
          item.parent_item = parent_item
          @items << item
        end
      end
      @items
    end

    def permit_params(*params)
      if params.empty?
        @permit_params
      else
        @permit_params.concat(params)
        self
      end
    end

    def item(type, *args, &block)
      item = Form::Item::Base.create(@config, type, *args, &block)
      item.parent_item = parent_item
      @items << item
      item
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dynamic_scaffold-1.12.2 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.12.1 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.12.0 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.11.0 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.10.0 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.9.0 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.8.1 lib/dynamic_scaffold/form_builder.rb
dynamic_scaffold-1.8.0 lib/dynamic_scaffold/form_builder.rb