Skip to content

Instantly share code, notes, and snippets.

@cthornton
Created July 3, 2014 03:55
Show Gist options
  • Save cthornton/31ca27be5ff857a00d10 to your computer and use it in GitHub Desktop.
Save cthornton/31ca27be5ff857a00d10 to your computer and use it in GitHub Desktop.
Blog
class ApiController < ApplicationController::Base
rescue_from ActiveRecord::RecordNotFound do |e|
render json: { error: e.message }, status: :not_found
end
rescue_from ActiveRecord::RecordInvalid do |invalid|
# You can even use jbuilder templates to make this cleaner!
render 'shared/record_invalid', locals: { exception: invalid },
status: :unprocessable_entity
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment