Module: ClientSideValidations::ActiveRecord::Uniqueness

Defined in:
lib/client_side_validations/active_record/uniqueness.rb

Instance Method Summary collapse

Instance Method Details

#client_side_hash(model, attribute) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/client_side_validations/active_record/uniqueness.rb', line 3

def client_side_hash(model, attribute)
  hash = {}
  hash[:message] = model.errors.generate_message(attribute, message_type, options.except(:scope))
  hash[:case_sensitive] = options[:case_sensitive]
  hash[:id] = model.id unless model.new_record?
  if options.key?(:scope) && options[:scope].present?
    hash[:scope] = Array.wrap(options[:scope]).inject({}) do |scope_hash, scope_item|
      scope_hash.merge!(scope_item => model.send(scope_item))
    end
  end

  unless model.class.name.demodulize == model.class.name
    hash[:class] = model.class.name.underscore
  end

  hash
end