Take the 2-minute tour ×

I'm using Devise and its confirm option.
As you know, a user won't be activated unless the user clicks on the link in Confirmation mail.

The problem I have here is, we can see all the members including the user who hasn't confirmed yet!

@users = User.all will fetch all the users! I don't want to include un-confirmed users.

Is there any technique to ignore those who haven't confirmed yet?
Adding something in User model will be the best!

Please help me:)

share|improve this question

3 Answers 3

up vote 1 down vote accepted

I'd recommend adding a scope to your User model for consistent access:

class User

  def self.unconfirmed
    where('users.confirmed_at is null')

  def self.confirmed
    where('users.confirmed_at is not null')


Then in controllers (or other models), this list can be accessed as:

@users = User.confirmed

The beauty of scopes is that they could be chained further:

@unformed_males = User.confirmed.where(:sex => 'male').order(:height)

You get the idea ;)


share|improve this answer
Thanks but your code is to fetch unconfirmed user. I want opposite. How can I exclude it? –  cat Jan 11 '13 at 15:09
Can you do the opposite? naming it confirmed please! –  cat Jan 11 '13 at 15:11
Edited answer :). Sorry for not reading your question better :( –  Nazar Jan 11 '13 at 15:12

Devise will give you the attribute confirmed_at. You can use:

@user = User.where('confirmed_at IS NOT NULL')

And, if I am not mistaken, after confirmation Devise sets the confirmation_token to NULL so that it can't be used again, so you could also do:

@user = User.where('confirmation_token IS NULL')
share|improve this answer

Devise adds confirmed_at column to your users table. So you can use as follows:

     @users = User.all(:conditions => ["confirmed_at is not null"])
share|improve this answer
No, this is old rails 2 syntax. Use User.where instead. –  Charles Jan 11 '13 at 14:41
He didn't mention any version. My answer is also correct. Why did you down vote –  codeit Jan 11 '13 at 14:42
If the user doesn't mention any version, I specifically encourage you to use the latest syntax. But nobody said I wouldn't upvote again if you corrected it ;-) –  Charles Jan 11 '13 at 14:44
But my code works in both rails 2 & 3. Your code is not :p –  codeit Jan 11 '13 at 15:00

Your Answer


