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 List | |
include MongoMapper::Document | |
key :name, String, :required => true | |
many :items | |
end | |
class Item | |
include MongoMapper::EmbeddedDocument |
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
# app/controllers/application_controller.rb | |
class ApplicationController < ActionController::Base | |
rescue_from(ActionController::RoutingError) { | |
render :template => 'errors/404' | |
} | |
end |
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
# 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 |
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
# 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 |
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
/ 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' } |
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
# 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' |
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
# 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 |
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
/ 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 || []; |
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
// 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); |
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
/ 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 |
OlderNewer