RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
rails -v rails plugin new uhoh --mountable rails g controller failures index rails g model failure message:text rake db:migrate rake uhoh:install:migrations cd test/dummy rails s # to start up the dummy app rails g controller simulate failure
module Uhoh class FailuresController < ApplicationController def index @failures = Failure.all end end end
<%= image_tag "uhoh/alert.png" %> <h1>Failures</h1> <ul> <% for failure in @failures %> <li><%= failure.message %></li> <% end %> </ul> <p><%= link_to "Failures", root_url %></p> <p><%= link_to "Simulate Failure", main_app.simulate_failure_path %></p>
root :to => "failures#index"
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload| if payload[:exception] name, message = *payload[:exception] Uhoh::Failure.create!(:message => message) end end
mount Uhoh::Engine => "/uhoh", :as => "uhoh_engine"
def failure # redirect_to uhoh_engine.root_url raise "Simulating an exception" end