Skip to content

Instantly share code, notes, and snippets.

@linko
Created September 23, 2014 11:43
Show Gist options
  • Save linko/b64b6c7f6f868e6652ca to your computer and use it in GitHub Desktop.
Save linko/b64b6c7f6f868e6652ca to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| Airbrake.notify(exception); render_error(500) }
rescue_from ActionView::MissingTemplate, ActiveRecord::RecordNotFound, ActionController::RoutingError,
ActionController::UnknownController, AbstractController::ActionNotFound, ActiveRecord::RecordNotFound,
ActionController::UnknownFormat, with: lambda { |exception| render_error(404) }
end
def routing_error
raise ActionController::RoutingError.new(params[:path])
end
private
def render_error(status)
respond_to do |format|
format.rss { render template: "errors/error_#{status}", formats: [:html], content_type: 'text/html' }
format.html { render template: "errors/error_#{status}" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment