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, #page, #resource

Class Method Summary collapse

Instance Method Summary collapse

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



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/administrate/field/has_one.rb', line 13

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

  { "#{attr}_attributes": related_dashboard_attributes }
end

Instance Method Details

#nested_formObject



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

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