How to purge anonymous guest users from DB

I am creating anonymous guest users which are persistent during the
time they are connected to the site or until they sign up and become a
member user …

this add a lot of anonymous user records in the DB and I wonder how to
purge them ? should I run a cron script regularly or is there another
way to do it ?

thanks for feedback

I have in my application_controller :

if user is logged in, return current_user, else return guest_user

def current_or_guest_user
if current_user
if session[:guest_user_id]
logging_in
guest_user.destroy
session[:guest_user_id] = nil
end
current_user
else
guest_user
end
end

find guest_user object associated with the current_session,

creating one if needed
def guest_user
User.find( session[:guest_user_id].nil? ? session[:guest_user_id]
= create_guest_user.id : session[:guest_user_id] )
end

def create_guest_user
u = User.new(email: “guest_#{Time.now.to_i}#{rand(99)}
@example.com”)
u.confirmed_at = Time.now
u.save(:validate => false, :confirm => false)
u
end

On Monday, September 10, 2012 1:43:35 PM UTC+1, Erwin wrote:

I am creating anonymous guest users which are persistent during the
time they are connected to the site or until they sign up and become a
member user …

this add a lot of anonymous user records in the DB and I wonder how to
purge them ? should I run a cron script regularly or is there another
way to do it ?

A nightly cronjob would be one way to do it. But do you really want to
delete them? It might be useful to keep these users, while they haven’t
signed up, their data may still be of value (eg for identifying why they
didn’t sign up)

Fred