gpt4 book ai didi

ruby-on-rails - 如何通过 devise_invitable 邀请现有用户

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:13 25 4
gpt4 key购买 nike

我实现了

gem 'devise_invitable' 

对于模型 User,我在邀请现有用户时遇到问题。错误显示 “USER IS ALREADY REGISTERED”。我想在另一个 User 邀请列表中添加相同的用户。如何做到这一点?

最佳答案

对于那些寻找相同问题的不同实现的人,您可以将新行为添加到 InvitationsController protected 方法 invite_resource

可以在 DeviseInvitable 上找到对下面示例的更详细的解释。维基页面,标题为 Invite a Resource (or User) that Has Already Signed Up without Invitation .

class Users::InvitationsController < Devise::InvitationsController

protected

# invite_resource is called when creating invitation
# should return an instance of resource class

# this is devise_invitable's implementation
# def invite_resource(&block)
# resource_class.invite!(invite_params, current_inviter, &block)
# end

def invite_resource(&block)
@user = User.find_by(email: invite_params[:email])
# @user is an instance or nil
if @user && @user.email != current_user.email
# invite! instance method returns a Mail::Message instance
@user.invite!(current_user)
# return the user instance to match expected return type
@user
else
# invite! class method returns invitable var, which is a User instance
resource_class.invite!(invite_params, current_inviter, &block)
end
end
end

关于ruby-on-rails - 如何通过 devise_invitable 邀请现有用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15470622/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com