Class: Administrate::Field::HasOne

Inherits:
Associative show all
Defined in:
lib/administrate/field/has_one.rb

Instance Attribute Summary

Attributes inherited from Base

#attribute, #data, #options, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Associative

associated_class, #associated_class, associated_class_name, #associated_class_name, association_primary_key_for, #display_associated_resource, foreign_key_for, reflection

Methods inherited from Base

associative?, field_type, html_class, #html_class, #initialize, #name, #read_value, #required?, searchable?, #to_partial_path, with_options

Constructor Details

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

Class Method Details

.eager_load?Boolean

Returns:



29
30
31
# File 'lib/administrate/field/has_one.rb', line 29

def self.eager_load?
  true
end

.permitted_attribute(attr, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/administrate/field/has_one.rb', line 6

def self.permitted_attribute(attr, options = {})
  resource_class = options[:resource_class]
  final_associated_class_name =
    if options.key?(:class_name)
      Administrate.warn_of_deprecated_option(:class_name)
      options.fetch(:class_name)
    elsif resource_class
      associated_class_name(resource_class, attr)
    else
      Administrate.warn_of_missing_resource_class
      if options
        attr.to_s.singularize.camelcase
      else
        attr
      end
    end
  related_dashboard_attributes =
    Administrate::ResourceResolver
      .new("admin/#{final_associated_class_name}")
      .dashboard_class.new.permitted_attributes + [:id]
  {"#{attr}_attributes": related_dashboard_attributes}
end

Instance Method Details

#html_controllerObject



51
52
53
# File 'lib/administrate/field/has_one.rb', line 51

def html_controller
  "select"
end

#linkable?Boolean

Returns:



47
48
49
# File 'lib/administrate/field/has_one.rb', line 47

def linkable?
  data.try(:persisted?)
end

#nested_formObject



33
34
35
36
37
38
# File 'lib/administrate/field/has_one.rb', line 33

def nested_form
  @nested_form ||= Administrate::Page::Form.new(
    resolver.dashboard_class.new,
    data || resolver.resource_class.new
  )
end

#nested_showObject



40
41
42
43
44
45
# File 'lib/administrate/field/has_one.rb', line 40

def nested_show
  @nested_show ||= Administrate::Page::Show.new(
    resolver.dashboard_class.new,
    data || resolver.resource_class.new
  )
end