From 948d7191f788fb206cb1547489155d9e86de24c1 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 4 Aug 2015 16:58:28 -0700 Subject: [PATCH] fixes #1582: Note API: attempting to create invalid note returns 200 OK --- app/controllers/notes_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index b03f57ef1..f8288d4aa 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -23,7 +23,11 @@ class NotesController < ApplicationController @note = Note.create(params[:note]) respond_with(@note) do |fmt| fmt.json do - render :json => @note.to_json(:methods => [:html_id]) + if @note.errors.any? + render :json => {:success => false, :reasons => @note.errors.full_messages}.to_json, :status => 422 + else + render :json => @note.to_json(:methods => [:html_id]) + end end end end @@ -33,7 +37,11 @@ class NotesController < ApplicationController @note.update_attributes(params[:note]) respond_with(@note) do |format| format.json do - render :json => @note.to_json + if @note.errors.any? + render :json => {:success => false, :reasons => @note.errors.full_messages}.to_json, :status => 422 + else + render :json => @note.to_json + end end end end