Class: Madmin::Fields::BelongsTo

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

Instance Attribute Summary

Attributes inherited from Madmin::Field

#attribute_name, #model, #options, #resource

Instance Method Summary collapse

Methods inherited from Madmin::Field

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

Constructor Details

This class inherits a constructor from Madmin::Field

Instance Method Details

#index_pathObject



17
18
19
# File 'lib/madmin/fields/belongs_to.rb', line 17

def index_path
  Madmin.resource_by_name(model.reflect_on_association(attribute_name).klass).index_path(format: :json)
end

#options_for_select(record) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/madmin/fields/belongs_to.rb', line 4

def options_for_select(record)
  if (record = record.send(attribute_name))
    resource = Madmin.resource_for(record)
    [[resource.display_name(record), record.id]]
  else
    []
  end
end

#to_paramObject



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

def to_param
  "#{attribute_name}_id"
end