This repository has been archived on 2024-12-01. You can view files and clone it, but cannot push or open issues or pull requests.
redmine_rodax_crm/app/models/recently_viewed.rb
2012-01-03 16:18:32 +00:00

23 lines
615 B
Ruby

class RecentlyViewed < ActiveRecord::Base
unloadable
RECENTLY_VIEWED_LIMIT = 5
belongs_to :viewer, :class_name => 'User', :foreign_key => 'viewer_id'
belongs_to :viewed, :polymorphic => true
validates_presence_of :viewed, :viewer
# after_save :increment_views_count
def self.last(limit=RECENTLY_VIEWED_LIMIT, usr=nil)
RecentlyViewed.find_all_by_viewer_id(usr || User.current, :limit => limit, :order => "#{RecentlyViewed.table_name}.updated_at DESC").collect{|v| v.viewed}.compact
end
private
def increment_views_count
self.increment!(:views_count)
end
end