From a438b487267f18a7bf88ceaf9088268194f6493f Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 12 Oct 2015 15:56:57 -0400 Subject: [PATCH] Need to unscope to get correct User.count --- app/models/user.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 00834d1..d185b02 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,7 @@ class User < ActiveRecord::Base rolify - after_create :set_admin, if: Proc.new { User.count == 1 } + after_create :set_admin, if: :first_user? def self.create_with_omniauth(auth) where(provider: auth[:provider], uid: auth[:uid]).first_or_create do |user| @@ -20,6 +20,12 @@ class User < ActiveRecord::Base self.has_role?(:moderator) end + def first_user? + User.unscoped do + User.count == 1 + end + end + private def set_admin