cbeer / devise-guests

fake 'em until you make 'em
MIT License
130 stars 31 forks source link

Persistent engagement with guest user #9

Closed dhirajbajaj closed 10 years ago

dhirajbajaj commented 11 years ago

I need to persistently track Guest users to do activities like comments; vote etc. Until they sign up One way is to : I can create/sign in the guest user using current_or_guest_user helper method and change their email when they sign up with password and show all their past activities.

Is there any other quick method to do that. Or are you planning to add same.

cbeer commented 11 years ago

There is a logging_in_user callback (replace user with whatever your devise model is called) that you can tap into to re-assign related items.

Eg.

class User < ActiveRecord::Base
    devise :database_authenticatable

   before_logging_in_user do 
     # run some queries to set user_id columns to current_user.id
   end

end

I'm open to pull requests that (optionally) do some model introspection to automate this, but I haven't had that need myself.

dhirajbajaj commented 11 years ago

I think this will work with unique lazy_id based on rand or timestamp: http://stackoverflow.com/questions/8267230/gradual-engagement-persistent-guest-user-with-devise

RKushnir commented 10 years ago

@cbeer Looks like that callback is defined in the controller, not model, right?