Find all users who haven't logged in for a while

Hi All,

In my application I have users that have a ‘last_login’ attribute. I’m
trying do a find for all users that have not logged in for over a
month but I’m having a little trouble figuring out how to do this with
activerecord. Does anyone know how to do this, or do I have to use SQL?

On Oct 9, 2007, at 7:24 , jeroen wrote:

I’m
trying do a find for all users that have not logged in for over a
month but I’m having a little trouble figuring out how to do this with
activerecord.

sql version

sql = <<-SQL
select *
from users
where last_login < current_timestamp - interval ‘1 month’
SQL
users_on_vacation = Users.find_by_sql(sql)

first ActiveRecord version

users_on_vacation = Users.find(:all, :conditions => [%(last_login <
current_timestamp - interval ‘1 month’)])

second ActiveRecord version

users_on_vacation = Users.find(:all, :conditions => [%(last_login
< ?), 1.month.ago])

Michael G.
grzm seespotcode net

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs