Rails: invite to sign up as friend with devise gem -


i'm using devise in rails app. want user can give link friends, , through link, can sign , become friends inviter.

here come with.

first, give every user unique code, dbgadf34t42a, , people visit url localhost/signup?invite_code=dbgadf34t42a. customize devise's sign controller, use code find inviter , create friendship relationship.

code like

  def create     #create user account, , create friendship     invite_code = paramsp[:invite_code]     if user.save       inviter = user.find_by_invite_code(invite_code)       inviter.friendships.create(friend: user)     end   end 

i'm wondering

  1. if there better way of doing this, gems or codes.
  2. i didn't find resources on customize devise's signup controller, can extract logic place, store invite code, , continue creating friendship model?

perhaps like:

  def after_sign_up     if params[:invite_code]       redirect_to new_friendship_path     else       # default_behavior     end   end 

  1. if there better way of doing this, gems or codes.

you may use devise-inviteable gem. friendship create can customize gem.

  1. i didn't find resources on customize devise's signup controller, can extract logic place, store invite code, , continue creating friendship model?

to customise devise signup need inherit devise::registrationscontroller

class registrationscontroller < devise::registrationscontroller    def create      super      # write customize code friendship    end end 

and tell devise use controller instead of default with:

# app/config/routes.rb devise_for :users, :controllers => {:registrations => "registrations"} 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -