Sha256: 4f1dd23224fec28f73cd7afcf8557c1c30fa2c5e2229aa2028463d17bb9f52e9
Contents?: true
Size: 1.31 KB
Versions: 12
Compression:
Stored size: 1.31 KB
Contents
module Plutonium module Core module Fields module Inputs class PolymorphicBelongsToAssociationInput < SimpleFormAssociationInput def render(view_context, f, record, **opts) opts = options.deep_merge opts f.input param, **opts end private def param :"#{reflection.name}_sgid" end def input_options { as: :grouped_select, label: reflection.name.to_s.humanize, collection: associated_classes.map { |klass| [klass.name, klass.all] }.to_h, group_label_method: :first, group_method: :last, include_blank: "Select One" } end def associated_classes Plutonium.eager_load_rails! associated_classes = [] ActiveRecord::Base.descendants.each do |model| next unless model.table_exists? model.reflect_on_all_associations(:has_many).each do |association| if association.options[:as] == reflection.name associated_classes << model.name end end end associated_classes end end end end end end
Version data entries
12 entries across 12 versions & 1 rubygems