Class: Administrate::Field::Polymorphic

Inherits:
BelongsTo show all
Defined in:
lib/administrate/field/polymorphic.rb

Instance Attribute Summary

Attributes inherited from Base

#attribute, #data, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BelongsTo

#associated_resource_options, #selected_option

Methods inherited from Associative

#associated_class, #display_associated_resource

Methods inherited from Base

#html_class, html_class, #initialize, #name, searchable?, #to_partial_path, with_options

Constructor Details

This class inherits a constructor from Administrate::Field::Base

Class Method Details

.permitted_attribute(attr, _options = nil) ⇒ Object



14
15
16
# File 'lib/administrate/field/polymorphic.rb', line 14

def self.permitted_attribute(attr, _options = nil)
  { attr => %i{type value} }
end

Instance Method Details

#associated_resource_grouped_optionsObject



6
7
8
9
10
11
12
# File 'lib/administrate/field/polymorphic.rb', line 6

def associated_resource_grouped_options
  classes.map do |klass|
    [klass.to_s, candidate_resources_for(klass).map do |resource|
      [display_candidate_resource(resource), resource.to_global_id]
    end]
  end
end

#permitted_attributeObject



18
19
20
# File 'lib/administrate/field/polymorphic.rb', line 18

def permitted_attribute
  { attribute => %i{type value} }
end

#selected_global_idObject



22
23
24
# File 'lib/administrate/field/polymorphic.rb', line 22

def selected_global_id
  data ? data.to_global_id : nil
end