Jeremy Ramos Jeremy Ramos - 1 year ago 73
Ruby Question

Using devise invitable. How to create the user only after the user has set his password

def create
if User.invite!(user_params)
flash[:success] = t('flashes.users.create_success')
flash[:error] = t('flashes.users.create_error')
redirect_to company_path(id: company.slug)

will create the user, then send an invitation to set a password. I only want it to send an invitation to set the password and then only persist the user if the user has set a password.

Answer Source

I would not mess with the devise invitable implementation like that.

Rather perhaps add a status column to the user using enums, so that you can isolate the users that have not accepted their invites and as one of the commenters said remove stale users later.

enum status: {invited: 0, accepted: 1}

then you can do the following:

User.invite!(status: "invited")

you will have to set the "accepted" status when the user accepts by hooking into the callbacks the gem provides (see

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download