本文介绍了如何邀请用户使用devise_invitable进行项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建应用程序,可以在其中邀请用户加入特定的项目/工作区/团队。但是默认情况下,它允许邀请用户加入应用程序,而不是特定项目。这个问题似乎非常相似
在这种情况下,有人知道如何覆盖 invitations_controller 吗?

I'm building the app, where users can be invited to a particular project/workspace/team. But by default it allows to invite users to the app, not a particular project. This question seems to be very similiar How to nest devise_invitable route to invite user to specific projectDoes anyone know, how to override invitations_controller in this case?

推荐答案

您可以在 projects_controller.rb 内创建邀请动作,然后邀请用户直接参加项目。

You can create an invite action inside your projects_controller.rb and invite the user directly to a project.

立即将受邀的用户项目相关联邀请后。以下是一个片段,可让您了解如何解决此问题。

Simply associate the invited User to a Project immediately after inviting. Here's a snippet to give you an idea of how you could approach this.

# POST /projects/:id/invite { name: "John Smith", email: "[email protected]" }
def invite
  # Set the current project
  @project = Project.find(param[:id])

  # Create your own strong_invite_params method to allow name and email
  invited_user = User.invite!(strong_invite_params, current_user)

  # If a simple belongs_to :project association
  invited_user.update(project: @project.id)

  # If a complex association through a separate projects_membership table
  invited_user.projects << @project
end

这篇关于如何邀请用户使用devise_invitable进行项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 13:33