From 36eb6cacb2be9c6cc42086d6e21f37b1a2df31a4 Mon Sep 17 00:00:00 2001 From: Linus Pettersson Date: Fri, 16 Aug 2013 23:37:30 +0200 Subject: [PATCH 1/2] Fixed unique count for Rails 4 --- app/models/impressionist/impressionable.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 2402e66..1626c83 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -29,7 +29,11 @@ module Impressionist def impressionist_count(options={}) options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date]) - options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) + if Rails::VERSION::MAJOR == 3 + options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) + else + options[:filter] == :all ? imps.count : imps.select(options[:filter]).distinct.count + end end def update_impressionist_counter_cache From acef02935c7fdc27c5ad66ee4d210d1f5f7713cd Mon Sep 17 00:00:00 2001 From: Linus Pettersson Date: Fri, 16 Aug 2013 23:42:03 +0200 Subject: [PATCH 2/2] Check for version 4 instead of 3 --- app/models/impressionist/impressionable.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/impressionist/impressionable.rb b/app/models/impressionist/impressionable.rb index 1626c83..71579f6 100644 --- a/app/models/impressionist/impressionable.rb +++ b/app/models/impressionist/impressionable.rb @@ -29,10 +29,10 @@ module Impressionist def impressionist_count(options={}) options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now) imps = options[:start_date].blank? ? impressions : impressions.where("created_at>=? and created_at<=?",options[:start_date],options[:end_date]) - if Rails::VERSION::MAJOR == 3 - options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) - else + if Rails::VERSION::MAJOR == 4 options[:filter] == :all ? imps.count : imps.select(options[:filter]).distinct.count + else + options[:filter] == :all ? imps.count : imps.count(options[:filter], :distinct => true) end end