Class: Madmin::Fields::NestedHasMany

Inherits:
Madmin::Field show all
Defined in:
lib/madmin/fields/nested_has_many.rb

Constant Summary collapse

DEFAULT_ATTRIBUTES =
%w[_destroy id].freeze

Instance Attribute Summary

Attributes inherited from Madmin::Field

#attribute_name, #model, #options

Instance Method Summary collapse

Methods inherited from Madmin::Field

#default_index_attributes, field_type, #initialize, #required?, #searchable?, #value, #visible?

Constructor Details

This class inherits a constructor from Madmin::Field

Instance Method Details

#nested_attributesObject



5
6
7
# File 'lib/madmin/fields/nested_has_many.rb', line 5

def nested_attributes
  resource.attributes.except(*skipped_fields)
end

#resourceObject



9
10
11
# File 'lib/madmin/fields/nested_has_many.rb', line 9

def resource
  "#{to_model.name}Resource".constantize
end

#to_modelObject



25
26
27
# File 'lib/madmin/fields/nested_has_many.rb', line 25

def to_model
  attribute_name.to_s.singularize.classify.constantize
end

#to_paramObject



13
14
15
# File 'lib/madmin/fields/nested_has_many.rb', line 13

def to_param
  {"#{attribute_name}_attributes": permitted_fields}
end

#to_partial_path(name) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/madmin/fields/nested_has_many.rb', line 17

def to_partial_path(name)
  unless %w[index show form fields].include? name
    raise ArgumentError, "`partial` must be 'index', 'show', 'form' or 'fields'"
  end

  "/madmin/fields/#{self.class.field_type}/#{name}"
end