Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added 404 handler and monitor

  • Loading branch information...
commit 4c35a92e84904c5f729003c3c4efed0d9252fb43 1 parent c14d478
activefx authored
View
13 app/controllers/four_oh_fours_controller.rb
@@ -0,0 +1,13 @@
+class FourOhFoursController < ApplicationController
+ def index
+ FourOhFour.add_request(request.url,
+ request.env['HTTP_REFERER'] || '')
+ 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
+
View
8 app/models/four_oh_four.rb
@@ -0,0 +1,8 @@
+class FourOhFour < ActiveRecord::Base
+ def self.add_request(url, referer)
+ request = find_or_initialize_by_url_and_referer(url, referer)
+ request.count += 1
+ request.save
+ end
+end
+
View
1  config/routes.rb
@@ -71,4 +71,5 @@
# Install the default routes as the lowest priority.
#map.connect ':controller/:action/:id'
#map.connect ':controller/:action/:id.:format'
+ map.connect '*path' , :controller => 'four_oh_fours'
end
View
17 db/migrate/20080910224435_create_four_oh_fours.rb
@@ -0,0 +1,17 @@
+class CreateFourOhFours < ActiveRecord::Migration
+ def self.up
+ create_table :four_oh_fours do |t|
+ t.string :url, :referer
+ t.integer :count, :default => 0
+ t.timestamps
+ end
+
+ add_index :four_oh_fours, [:url, :referer], :unique => true
+ add_index :four_oh_fours, [:url]
+ end
+
+ def self.down
+ drop_table :four_oh_fours
+ end
+end
+
View
21 db/schema.rb
@@ -9,7 +9,18 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20080813053928) do
+ActiveRecord::Schema.define(:version => 20080910224435) do
+
+ create_table "four_oh_fours", :force => true do |t|
+ t.string "url"
+ t.string "referer"
+ t.integer "count", :default => 0
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "four_oh_fours", ["url", "referer"], :name => "index_four_oh_fours_on_url_and_referer", :unique => true
+ add_index "four_oh_fours", ["url"], :name => "index_four_oh_fours_on_url"
create_table "logged_exceptions", :force => true do |t|
t.string "exception_class"
@@ -37,6 +48,14 @@
t.string "salt", :null => false
end
+ create_table "pages", :force => true do |t|
+ t.string "title"
+ t.string "body"
+ t.integer "user_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "roles", :force => true do |t|
t.string "name"
end
Please sign in to comment.
Something went wrong with that request. Please try again.