Sha256: d918a69477703f14829f58a7c5b2485014b0427831cbf095bbd9ed7ce1676f8a

Contents?: true

Size: 1.18 KB

Versions: 25

Compression:

Stored size: 1.18 KB

Contents

require 'rails_admin/config/fields/association'

module RailsAdmin
  module Config
    module Fields
      module Types
        class HasOneAssociation < RailsAdmin::Config::Fields::Association
          # Register field type for the type loader
          RailsAdmin::Config::Fields::Types.register(self)

          register_instance_option :partial do
            nested_form ? :form_nested_one : :form_filtering_select
          end

          # Accessor for field's formatted value
          register_instance_option :formatted_value do
            (o = value) && o.send(associated_model_config.object_label_method)
          end

          register_instance_option :inline_add do
            true
          end

          register_instance_option :inline_edit do
            true
          end

          def editable?
            (nested_form || abstract_model.model.new.respond_to?("#{name}_id=")) && super
          end

          def selected_id
            value.try :id
          end

          def method_name
            nested_form ? "#{name}_attributes".to_sym : "#{name}_id".to_sym
          end

          def multiple?
            false
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
rails_admin-2.3.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.3.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.2.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.2.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.1.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.1.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.0.2 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.4.3 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.0.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.0.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.0.0.rc lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-2.0.0.beta lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.3.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.2.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.1.1 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.1.0 lib/rails_admin/config/fields/types/has_one_association.rb
rails_admin-1.0.0 lib/rails_admin/config/fields/types/has_one_association.rb