3

I followed these instructions to check whether a user has been soft-deleted or not when logging in. In the example below I can check for a boolean value:

Class User < ActiveRecord::Base
  def self.find_for_authentication(conditions)
    super(conditions.merge(:deleted_flag => false))
  end

I would prefer a timestamp (created_at) field. How can I check whether such a field is empty? The database throws errors for the following checks:

super(conditions.merge(:deleted_at => false)) # also tried nil, "NULL" and "IS NULL"
2
  • Did you try :deleted_at => None or none? Commented Oct 17, 2012 at 14:50
  • Thanks, didn't work, it says undefined local variable or undefined constant Commented Oct 17, 2012 at 14:59

1 Answer 1

11

You can't using this solution, without modifying devise of course. Devise will send your conditions directly to the database, so no way of calling a method or using a library like squeel (that will allow something like where{created_at == nil}.

You could use the solution provided in How to "soft delete" user with Devise, but the error message will be: "You have to confirm your account before continuing."

Add this to your resource model:

  def inactive_message
    !!deleted_at ? :deleted : super
  end

And add a message to your locales:

en:
  devise:
    failure:
      deleted: "Your account was deleted."

I hope it helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.