Rails ActiveRecord: Find All Users Except Current User
Posted
by SingleShot
on Stack Overflow
See other posts from Stack Overflow
or by SingleShot
Published on 2010-04-20T05:23:34Z
Indexed on
2010/04/20
5:33 UTC
Read the original article
Hit count: 280
I feel this should be very simple but my brain is short-circuiting on it. If I have an object representing the current user, and want to query for all users except the current user, how can I do this, taking into account that the current user can sometimes be nil
?
This is what I am doing right now:
def index
@users = User.all
@users.delete current_user
end
What I don't like is that I am doing post-processing on the query result. Besides feeling a little wrong, I don't think this will work nicely if I convert the query over to be run with will_paginate
. Any suggestions for how to do this with a query? Thanks.
© Stack Overflow or respective owner