Sha256: 58b9718203afa895415142a1975720c3215c7c1d582fc077e449d1b724384c3f

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 Bytes

Contents

require_relative "associative"

module Administrate
  module Field
    class BelongsTo < Associative
      def self.permitted_attribute(attr)
        :"#{attr}_id"
      end

      def permitted_attribute
        self.class.permitted_attribute(attribute)
      end

      def associated_resource_options
        [nil] + candidate_resources.map do |resource|
          [display_candidate_resource(resource), resource.send(primary_key)]
        end
      end

      def selected_option
        data && data.send(primary_key)
      end

      private

      def candidate_resources
        associated_class.all
      end

      def display_candidate_resource(resource)
        associated_dashboard.display_resource(resource)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
administrate-0.8.1 lib/administrate/field/belongs_to.rb
administrate-0.8.0 lib/administrate/field/belongs_to.rb
administrate-0.7.0 lib/administrate/field/belongs_to.rb
administrate-0.6.0 lib/administrate/field/belongs_to.rb
administrate-0.5.0 lib/administrate/field/belongs_to.rb
administrate-0.4.0 lib/administrate/field/belongs_to.rb