Sha256: 9e45476963bd24b6f2a19eb6e81c59646dd29abefbd748f86c6c9e60100d37d5

Contents?: true

Size: 491 Bytes

Versions: 4

Compression:

Stored size: 491 Bytes

Contents

module Tuning
  module Extensions
    module ActiveRecord
      module Base
        extend ActiveSupport::Concern

        included do
          before_save :nilify_blank_attributes
          alias_method :validate, :valid?
        end

        private

        def nilify_blank_attributes
          attributes.each do |column, value|
            if value.is_a?(String) and value.blank?
              self[column] = nil
            end
          end
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tuning-5.1.3 lib/tuning/extensions/active_record/base.rb
tuning-5.1.2 lib/tuning/extensions/active_record/base.rb
tuning-5.1.0 lib/tuning/extensions/active_record/base.rb
tuning-4.0.1.2 lib/tuning/extensions/active_record/base.rb