facebook - How do rails app have invite your friends custom url? -
i using devise_invitable submit email invites new user. each email send out creates unique token gets connects 2 users if accept invitation. each current_user have unique invitation token stays same can tweet it, email it, etc. , accepts invite clicking on link (www.mydomain.com/signup/'unique_current_user_token') taken signup form store token in 'account' can see invited them. make
you may want manually overriding registration page of devise , allowing our new parameters model (attr_accessible rails 3 or params.require(:foo).permit)
first should remove devise invitable not use approach i've searched , did not find clean way devise_invitable.
step 2: add attribute users table called invitation_token (this 1 different devise invitable unique per user , used send invitation not used when receiving invitation)
and add user model (according rails casts)
before_create :generate_invitation_token def generate_invitation_token self.invitation_token = digest::sha1.hexdigest([time.now, rand].join) end by each user have unique invitation_token
step 3: can have url /signup/:invitation_token invite users unique per user (you should add routes , map devise::registrationscontroller#create)
step 4: accept users , recognize invited them on registration
now have override devise::registrationscontroller#create , new , view
in new should find user invited. , add virtual attribute should reference user ie: inviter.id
and add hidden_field registration form set such attribute
now in create check availability of attribute if present can ever want (add relation between users in case).
and that's think if need else comment , edit answer more
Comments
Post a Comment