我已经通过覆盖邀请控制器来完成此操作,执行此操作的说明在 github 上的 devise_invitable 主页中,因此我不会在这里进行介绍。
为了安全起见,我创建了一个包含额外邀请信息的新表,以便电子邮件接受链接不包含群组链接(我的群组仅通过私人邀请进行,因此我不希望受邀用户更改邀请 url在电子邮件中,并可能添加其他未受邀的组)。
devise_invitable 在用户表中创建新表后,通过用户 id 对新表进行索引。
class Users::InvitesController < Devise::InvitationsController
.
.
def create
# make sure the current user is connected to this object for security
if @object.has_connection_with(current_user)
# perform the invite
self.resource = resource_class.invite!(params[resource_name], current_inviter)
#since we invite based on object, we must reference this object once the user accepts, so we store this in our Invites table
object_invite = Invite.new(:invitable_type => @object.class.name, :invitable_id => @object.id, :user_id => self.resource.id, :inviter_id => current_inviter.profile.id)
object_invite.save!
if resource.errors.empty?
set_flash_message :notice, :send_instructions, :email => self.resource.email
#respond_with resource, :location => after_invite_path_for(resource)
render :json => {:status => 'success'} and return
else
respond_with_navigational(resource) { render_with_scope :new }
end
end
end
然后在您的更新方法中(同样在同一个控制器中)您可以找到()邀请记录并提取允许您将新用户连接到组的所需信息。
剩下的唯一问题是如何向电子邮件添加其他参数,例如组名,我还没有解决。