Need to unscope to get correct User.count
This commit is contained in:
parent
eee6f9f995
commit
a438b48726
1 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue