Skip to content

Instantly share code, notes, and snippets.

View accuser's full-sized avatar

Matthew Gibbons accuser

View GitHub Profile
class List
include MongoMapper::Document
key :name, String, :required => true
many :items
end
class Item
include MongoMapper::EmbeddedDocument
# 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'
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/errors_controller.rb
class ErrorsController < ApplicationController
ERRORS = [
:internal_server_error,
:not_found,
:unprocessable_entity
].freeze
ERRORS.each do |e|
define_method e do
/ 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/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'
# 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/views/layouts/application.html.haml
%html
%head
%title My Great Site
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= javascript_include_tag :defaults
%body
#content= yield
:javascript
var _gaq = _gaq || [];
// public/javascripts/application.js
var _gaq = _gaq || [];
$(document).ready(function() {
_gaq.push(['_setAccount', 'UA-XXXXXXX-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
/ app/views/layouts/application.html.haml
%html{ :data => { :web_property_id => 'UA-XXXXXXX-1' } }
%head
%title My Great Site
= stylesheet_link_tag 'screen.css', :media => 'screen, projection'
= javascript_include_tag :defaults
%body
#content= yield