Permalink
Browse files

Added Link.total_visits class method

  • Loading branch information...
1 parent eaea3ae commit dda1fce01a5dbd254f4bb8254d8f840000ab361c @nmanzi committed Oct 7, 2011
Showing with 8 additions and 0 deletions.
  1. +8 −0 app/models/link.rb
View
@@ -6,6 +6,14 @@ class Link < ActiveRecord::Base
validates :url, :presence => true, :url => true
before_save :set_defaults
+ def self.total_visits
+ total_visits = 0
+ self.all.each do |item|
+ total_visits += item.visits
+ end
+ return total_visits
+ end
+
def set_defaults
self.visits ||= 0
end

0 comments on commit dda1fce

Please sign in to comment.