Class: StatisticsCollectorController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/statistics_collector_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/statistics_collector_controller.rb', line 2

def index
  if klass = params[:type].classify.constantize
    cookie_name = "seen_#{params[:type].pluralize}".to_sym
    if object = klass.find_by_id(params[:id]) and
      (cookies[cookie_name].blank? or
       !cookies[cookie_name].split(',').include?(object.id.to_s))
      object.viewed_counters.new.increment_counter
      cookies[cookie_name] = {
        :value => (cookies[cookie_name] || '') + ",#{object.id}",
        :expires => Date.current.end_of_day
      }
    end
  end
  render(:nothing => true)
end