class Administrate::Field::HasOne

Public Class Methods

eager_load?() click to toggle source
# File lib/administrate/field/has_one.rb, line 29
def self.eager_load?
  true
end
permitted_attribute(attr, options = {}) click to toggle source
# 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

Public Instance Methods

linkable?() click to toggle source
# File lib/administrate/field/has_one.rb, line 47
def linkable?
  data.try(:persisted?)
end
nested_form() click to toggle source
# 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_show() click to toggle source
# 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

Private Instance Methods

resolver() click to toggle source
# File lib/administrate/field/has_one.rb, line 53
def resolver
  @resolver ||=
    Administrate::ResourceResolver.new("admin/#{associated_class.name}")
end