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