Skip to content

Instantly share code, notes, and snippets.

@etozzato
Created November 27, 2009 17:18
Show Gist options
  • Save etozzato/244131 to your computer and use it in GitHub Desktop.
Save etozzato/244131 to your computer and use it in GitHub Desktop.
class FailController < ApplicationController
def index
Fail.add_request(request.host, request.path, request.env['HTTP_REFERER'] || '', request.remote_ip || "0.0.0.0")
respond_to do |format|
format.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
format.all { render :nothing => true, :status => "404 Not Found" }
end
end
end
class Fail < ActiveRecord::Base
def self.add_request(host, path, referrer, ip)
fail = find_or_initialize_by_host_and_path_and_referer(host, path, referrer)
fail.count = 1 + fail.count
fail.save
UserMailer.deliver_root("Got FAIL!", "Host #{host}, Path #{path}, Referer #{referrer}, IP #{ip}, count #{fail.count}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment