Permalink
Browse files

Use Sequel Timestamps plugin to generated created_at and updated_at

  • Loading branch information...
1 parent 85aeb12 commit c893de2ad7dee842cf8cc9ea6b33658cc3aa833c @dmac committed Aug 16, 2012
Showing with 2 additions and 13 deletions.
  1. +2 −13 lib/db.rb
View
@@ -2,19 +2,8 @@
require "pathological"
require "environment"
-class Sequel::Model
- def before_create
- now = Time.now
- self.created_at ||= now if self.columns.include?(:created_at)
- self.updated_at = now if self.columns.include?(:updated_at)
- super
- end
-
- def after_save
- super
- self.updated_at = Time.now if self.columns.include?(:updated_at)
- end
-end
+# Timestamp all models with created_at and updated_at.
+Sequel::Model.plugin :timestamps
DB = Sequel.postgres(:host => DB_HOST, :user => DB_USER, :password => DB_PASS, :database => DB_NAME)

0 comments on commit c893de2

Please sign in to comment.