Class: RailsAdmin::Config::Fields::SingularAssociation

Inherits:
Association show all
Defined in:
lib/rails_admin/config/fields/singular_association.rb

Constant Summary

Constants inherited from Base

Base::NAMED_INSTANCE_VARIABLES

Instance Attribute Summary

Attributes inherited from Base

#abstract_model, #defined, #name, #order, #parent, #properties, #root, #section

Instance Method Summary collapse

Methods inherited from Association

#associated_model_config, #associated_model_limit, #associated_object_label_method, #associated_prepopulate_params, #associated_primary_key, #association, #dynamic_scope_relationships, #method_name, #polymorphic?, #value, #virtual?

Methods inherited from Base

#association?, #eager_load_values, #editable?, #errors, #filter_options, #form_default_value, #generic_field_help, #generic_help, #initialize, #inverse_of, #method_name, #optional, #optional=, #optional?, #parse_value, #sort_column, #type, #type_css_class, #value, #virtual?

Methods included from Inspectable

#inspect

Methods included from Groupable

#group

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, included, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#bindings, #bindings=, #with

Constructor Details

This class inherits a constructor from RailsAdmin::Config::Fields::Base

Instance Method Details

#collection(scope = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rails_admin/config/fields/singular_association.rb', line 21

def collection(scope = nil)
  if associated_collection_cache_all || scope
    super
  else
    [[formatted_value, selected_id]]
  end
end

#form_valueObject



45
46
47
# File 'lib/rails_admin/config/fields/singular_association.rb', line 45

def form_value
  form_default_value.nil? ? selected_id : form_default_value
end

#multiple?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rails_admin/config/fields/singular_association.rb', line 29

def multiple?
  false
end

#parse_input(params) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rails_admin/config/fields/singular_association.rb', line 37

def parse_input(params)
  return unless nested_form && params[method_name].try(:[], :id).present?

  ids = associated_model_config.abstract_model.parse_id(params[method_name][:id])
  ids = ids.to_composite_keys.to_s if ids.respond_to?(:to_composite_keys)
  params[method_name][:id] = ids
end

#selected_idObject

Raises:

  • (NoMethodError)


33
34
35
# File 'lib/rails_admin/config/fields/singular_association.rb', line 33

def selected_id
  raise NoMethodError # abstract
end

#widget_optionsObject



49
50
51
52
53
54
55
# File 'lib/rails_admin/config/fields/singular_association.rb', line 49

def widget_options
  {
    xhr: !associated_collection_cache_all,
    remote_source: bindings[:view].index_path(associated_model_config.abstract_model, source_object_id: abstract_model.format_id(bindings[:object].id), source_abstract_model: abstract_model.to_param, associated_collection: name, current_action: bindings[:view].current_action, compact: true),
    scopeBy: dynamic_scope_relationships,
  }
end