Module: JsClientBridge::Responses::Validation

Included in:
JsClientBridge::Responses
Defined in:
lib/js-client-bridge/responses/validation.rb

Instance Method Summary collapse

Instance Method Details

#respond_with_validation_error(*args) ⇒ Object

Generates a validation error status response. If the first parameter is a string is will be used as the _status options. It will also honour custom optionss as long they don’t clash with the standard ones.

Parameters

message<String>

An optional message.

options<Hash>

Custom optionss.

Returns

JSON String


16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/js-client-bridge/responses/validation.rb', line 16

def respond_with_validation_error(*args)
  obj = args.shift
  options = args.last.is_a?(Hash) ? args.pop : {}

  # Generate our response hash and add the exceptions parameter
  response =  if options.include?(:message)
                options.merge( validation_errors_to_hash(obj, options.delete(:message)) )
              else
                options.merge( validation_errors_to_hash(obj) )
              end

  format_response(response, options)
end