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
>
> 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
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/huB4--RZ7DEJ.
For more options, visit https://groups.google.com/groups/opt_out.