class RailsAdmin::Config::Fields::Group

A container for groups of fields in edit views

Attributes

abstract_model[R]
name[R]
parent[R]
root[R]
section[RW]

Public Class Methods

new(parent, name) click to toggle source
# File lib/rails_admin/config/fields/group.rb, line 20
def initialize(parent, name)
  @parent = parent
  @root = parent.root

  @abstract_model = parent.abstract_model
  @section = parent
  @name = name.to_s.tr(' ', '_').downcase.to_sym
end

Public Instance Methods

field(name, type = nil, &block) click to toggle source

Defines a configuration for a field by proxying parent’s field method and setting the field’s group as self

@see RailsAdmin::Config::Fields.field

# File lib/rails_admin/config/fields/group.rb, line 33
def field(name, type = nil, &block)
  field = section.field(name, type, &block)
  # Directly manipulate the variable instead of using the accessor
  # as group probably is not yet registered to the parent object.
  field.instance_variable_set('@group', self)
  field
end
fields() click to toggle source

Reader for fields attached to this group

# File lib/rails_admin/config/fields/group.rb, line 42
def fields
  section.fields.select { |f| f.group == self }
end
fields_of_type(type, &block) click to toggle source

Defines configuration for fields by their type

@see RailsAdmin::Config::Fields.fields_of_type

# File lib/rails_admin/config/fields/group.rb, line 49
def fields_of_type(type, &block)
  selected = section.fields.select { |f| type == f.type }
  selected.each { |f| f.instance_eval(&block) } if block
  selected
end
visible_fields() click to toggle source

Reader for fields that are marked as visible

# File lib/rails_admin/config/fields/group.rb, line 56
def visible_fields
  section.with(bindings).visible_fields.select { |f| f.group == self }
end