How to invite a user to project with devise_invitable?

主宰稳场 提交于 2019-12-04 15:31:21

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: "john@email.com" }
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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!