Skip to content

Instantly share code, notes, and snippets.

View accuser's full-sized avatar

Matthew Gibbons accuser

View GitHub Profile
# config/environment/production.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)
module Example
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
rescue_from(ActionController::RoutingError) {
render :template => 'errors/404'
}
end
# config/initializers/show_exceptions.rb
require 'action_dispatch/middleware/show_exceptions'
/ app/views/errors/not_found.html.haml
%h1 The page you were looking for doesn't exist.
%p
You may have mistyped the address or the page may have moved.
%script{ :type => 'text/javascript' }
var GOOG_FIXURL_LANG = '#{I18n.locale}';
var GOOG_FIXURL_SITE = '#{request.protocol}#{request.host}';
%script{ :type => 'text/javascript', :src => 'http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js' }
# app/controllers/errors_controller.rb
class ErrorsController < ApplicationController
ERRORS = [
:internal_server_error,
:not_found,
:unprocessable_entity
].freeze
ERRORS.each do |e|
define_method e do
# config/initializers/show_exceptions.rb
require 'action_dispatch/middleware/show_exceptions'
module ActionDispatch
class ShowExceptions
private
def render_exception_with_template(env, exception)
body = ErrorsController.action(rescue_responses[exception.class.name]).call(env)
log_error(exception)
body
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
rescue_from(ActionController::RoutingError) {
render :template => 'errors/404'
}
end
class List
include MongoMapper::Document
key :name, String, :required => true
many :items
end
class Item
include MongoMapper::EmbeddedDocument