How to disable search queries when searching a user in a database

Does anyone know how to disable search queries when (authenticating or verifying) a user on every request?

Let's say I have this scoped user model

class User < ActiveRecord::Base
  default_scope where(group_id: 1)
end

      

I already got unscope on authentication by overriding the method find_for_authentication

:

def self.find_for_authentication(conditions)
  User.unscoped { super }
end

      

But when I go to any page that has a filter :authenticate_user!

, select logs from user because it uses scope. I also tried to disable the method active_for_authentication?

, but it didn't work.

Does anyone know where Devise is displaying the current user from the database in every request for a page that is filtered :authenticate_user!

?

I am using Rails 3.2.1 and Devise 2.0.

+3


source to share


2 answers


You can override the method current_user

in the file application_controller.rb

:



def current_user
  User.unscoped { super }
end

      

+1


source


Another way:

class User < ActiveRecord::Base
  def self.serialize_from_session(key, salt)
    self.unscoped { super }
  end
end

      



See: fooobar.com/questions/1895663 / ...

0


source







All Articles