Followed along with Railscast 053 Handling Exceptions
Ruby CSS JavaScript CoffeeScript
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
bin
config
db
lib
log
public
test
vendor/assets
.gitignore
Gemfile
Gemfile.lock
README.md
Rakefile
config.ru

README.md

053 Handling Exceptions

Followed along with Railscast 053 Handling Exceptions

Blog Post @ PatrickPerey.com

class Forbidden < StandardError; end
...
def show
  raise Forbidden, 'You are not allowed to access this product.'
end
config.exceptions_app = self.routes
match '(errors)/:status', to: 'errors#show', constraints: {status: /\d{3}/}, via: :get
class ErrorsController < ApplicationController
  def show
    @exception = env["action_dispatch.exception"]
    respond_to do |format|
      format.html { render action: request.path[1..-1] }
      format.json { render json: {status: request.path[1..-1], error: @exception.message} }
    end
  end
end