lib/faceted/controller.rb in faceted-1.0.8 vs lib/faceted/controller.rb in faceted-1.1.0

- old
+ new

@@ -2,35 +2,35 @@ module Controller # For rendering a response with a single object, e.g. # render_response(@address) - def render_response(obj) + def render_response(obj, code=nil) render :json => { success: obj.success, response: obj.to_hash, errors: obj.errors - } + }, :status => code || obj.success ? 200 : 400 end # For rendering a response with a multiple objects, e.g. # render_response_with_collection(:addresses, @addresses) def render_response_with_collection(key, array) render :json => { success: true, response: {"#{key}".to_sym => array}, - errors: nil + errors: nil } end # In your base API controller: # rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found def render_400(exception) render :json => { success: false, response: nil, - errors: "Record not found: #{exception.message}" - }, :status => 404 + errors: "#{exception.message}" + }, :status => 400 end # In your base API controller: # rescue_from Exception, :with => :render_500 def render_500(exception) \ No newline at end of file