Sha256: 8e1b7832de6fb8d07316dbe7654dfb6291fb320248d824ecfd7df697a7b15737

Contents?: true

Size: 736 Bytes

Versions: 3

Compression:

Stored size: 736 Bytes

Contents

require_relative "associative"

module Administrate
  module Field
    class HasOne < Associative
      def initialize(attribute, data, page, options = {})
        resolver = Administrate::ResourceResolver.new("admin/#{attribute}")
        @nested_form = Administrate::Page::Form.new(
          resolver.dashboard_class.new,
          data || resolver.resource_class.new,
        )

        super
      end

      def self.permitted_attribute(attr)
        related_dashboard_attributes =
          Administrate::ResourceResolver.new("admin/#{attr}").
            dashboard_class.new.permitted_attributes + [:id]

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

      attr_reader :nested_form
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
semantic-administrate-0.1.0 lib/administrate/field/has_one.rb
administrate-0.8.1 lib/administrate/field/has_one.rb
administrate-0.8.0 lib/administrate/field/has_one.rb