fixes #1582: Note API: attempting to create invalid note returns 200 OK
This commit is contained in:
@@ -23,20 +23,28 @@ class NotesController < ApplicationController
|
|||||||
@note = Note.create(params[:note])
|
@note = Note.create(params[:note])
|
||||||
respond_with(@note) do |fmt|
|
respond_with(@note) do |fmt|
|
||||||
fmt.json do
|
fmt.json do
|
||||||
|
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])
|
render :json => @note.to_json(:methods => [:html_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@note = Note.find(params[:id])
|
@note = Note.find(params[:id])
|
||||||
@note.update_attributes(params[:note])
|
@note.update_attributes(params[:note])
|
||||||
respond_with(@note) do |format|
|
respond_with(@note) do |format|
|
||||||
format.json do
|
format.json do
|
||||||
|
if @note.errors.any?
|
||||||
|
render :json => {:success => false, :reasons => @note.errors.full_messages}.to_json, :status => 422
|
||||||
|
else
|
||||||
render :json => @note.to_json
|
render :json => @note.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@note = Note.find(params[:id])
|
@note = Note.find(params[:id])
|
||||||
|
|||||||
Reference in New Issue
Block a user