Class: ActiveModel::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_api_validation_errors/active_model_errors.rb

Constant Summary collapse

@@translate_message =

Option to specify wether to return hash or translation. Defaults to true to keep original behaviour.

true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disable_translationsObject



10
11
12
# File 'lib/rails_api_validation_errors/active_model_errors.rb', line 10

def self.disable_translations
  @@translate_message = false
end

.enable_translationsObject



14
15
16
# File 'lib/rails_api_validation_errors/active_model_errors.rb', line 14

def self.enable_translations
  @@translate_message = true
end

Instance Method Details

#_generate_messageObject

Keep original method



19
# File 'lib/rails_api_validation_errors/active_model_errors.rb', line 19

alias _generate_message generate_message

#generate_message(attribute, type = :invalid, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/rails_api_validation_errors/active_model_errors.rb', line 21

def generate_message(attribute, type = :invalid, options = {})
  if @@translate_message
    _generate_message(attribute, type, options)
  else
    type = options.delete(:message) if options[:message].is_a?(Symbol)

    { :message => type, :meta => options }
  end
end