1
0
Fork 0

Need to unscope to get correct User.count

This commit is contained in:
Andrew Tomaka 2015-10-12 15:56:57 -04:00
parent eee6f9f995
commit a438b48726

View file

@ -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