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 project Does anyone know, how to override invitations_controller in this case?
Asked
Active
Viewed 811 times
1 Answers
1
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

Igor P
- 629
- 1
- 7
- 9
-
Not sure whether creating the users we invite before they even accept is a good choice – Stéphane Bruckert Oct 20 '17 at 09:28