Created
July 3, 2014 03:55
-
-
Save cthornton/31ca27be5ff857a00d10 to your computer and use it in GitHub Desktop.
Blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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