By setting your rails controller as:
respond_to :json
You can easily receive errors in JSON format (just make sure to use respond_with(object))
class XYZController < ApplicationController
respond_to :html, :json
responders :jsons
def create
@xyz = Xyz.new( params[:xyz] )
@xyz.save
respond_with @xyz, :location=>@xyz.id.nil? ? "" : edit_xyz_url(@xyz)
end
A custom JSON responder was implemented specifically for handling Backbone interactions:
module Responders
module JsonResponder
def to_json
raise error unless resourceful?
if get?
display resource
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
elsif post?
display resource, :status => :created, :location => api_location
elsif put?
display resource, :status=>:ok, :location => api_location
elsif has_empty_resource_definition?
display empty_resource, :status => :ok
else
head :ok
end
end
end
end