summaryrefslogtreecommitdiffstats
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index fbdb1d301..4b4e04cd0 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -637,12 +637,14 @@ class ApplicationController < ActionController::Base
end
# Renders API response on validation failure
+ # for an object or an array of objects
def render_validation_errors(objects)
- if objects.is_a?(Array)
- @error_messages = objects.map {|object| object.errors.full_messages}.flatten
- else
- @error_messages = objects.errors.full_messages
- end
+ messages = Array.wrap(objects).map {|object| object.errors.full_messages}.flatten
+ render_api_errors(messages)
+ end
+
+ def render_api_errors(*messages)
+ @error_messages = messages.flatten
render :template => 'common/error_messages.api', :status => :unprocessable_entity, :layout => nil
end