Sha256: 8091381e3d5dad5b8b704b5d6840e10bac1f7b2db4309f45b7d83ac52fcef871
Contents?: true
Size: 931 Bytes
Versions: 6
Compression:
Stored size: 931 Bytes
Contents
module Madmin module Fields class NestedHasMany < Field DEFAULT_ATTRIBUTES = %w[_destroy id].freeze def nested_attributes resource.attributes.except(*skipped_fields) end def resource "#{to_model.name}Resource".constantize end def to_param {"#{attribute_name}_attributes": permitted_fields} end 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 def to_model attribute_name.to_s.singularize.classify.constantize end private def permitted_fields (resource.permitted_params - skipped_fields + DEFAULT_ATTRIBUTES).uniq end def skipped_fields options[:skip] || [] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems