Sha256: 2fa9ea1f931aab913a94ecd7066e1d42a1b4d3e8fbf7d6c9016223e2acfe542a
Contents?: true
Size: 1.31 KB
Versions: 8
Compression:
Stored size: 1.31 KB
Contents
# frozen_string_literal: true ActiveSupport.on_load(:active_record) do module ActiveRecord class Base def self.rails_admin(&block) RailsAdmin.config(self, &block) end def rails_admin_default_object_label_method new_record? ? "new #{self.class}" : "#{self.class} ##{id}" end def safe_send(value) if has_attribute?(value) read_attribute(value) else send(value) end end end end if defined?(CompositePrimaryKeys) # Apply patch until the fix is released: # https://github.com/composite-primary-keys/composite_primary_keys/pull/572 CompositePrimaryKeys::CompositeKeys.class_eval do alias_method :to_param, :to_s end CompositePrimaryKeys::CollectionAssociation.prepend(Module.new do def ids_writer(ids) if reflection.association_primary_key.is_a? Array ids = CompositePrimaryKeys.normalize(Array(ids).reject(&:blank?), reflection.association_primary_key.size) reflection.association_primary_key.each_with_index do |primary_key, i| pk_type = klass.type_for_attribute(primary_key) ids.each do |id| id[i] = pk_type.cast(id[i]) if id.is_a? Array end end end super ids end end) end end
Version data entries
8 entries across 8 versions & 1 rubygems