How to insert a devise_invitable route to invite a user to a specific project

Problem

I use devise and devise_invitable gems in a project management web application. I successfully invite new users to the web application.

But I need to invite new users to a specific project and I can’t understand how to do this. I need a project ID as part of the route, so I can correctly connect the controller code.

Context

The corresponding routes.rb section is as follows:

 devise_for :users, :controllers => { :invitations => "invitations" } 

So:

  • users/invitation/new works for new invitations.
  • My own invitations_controller.rb overrides the default value of InvitationsController
  • I have :projects as a resource that I use, for example

      resources :projects do resources :milestones, :task ... etc end 

(I think) I want to do something like this work:

 users/invitation/projects/4f3423d34323/new 
+4
source share
1 answer

The current approach is to specify a route using devise_scope :

 devise_for :users, :controllers => { :invitations => "invitations" } devise_scope :user do match "/projects/:project_id/invitations/new", :to => "invitations#new", :via => "get", :as => "new_project_invitation" end 

This means that I can use:

Case 1: users/invitation/new (to invite a new user to a web application)

and

Case 2: projects/:project_id/invitations/new (to invite a new user to a web application + project)

invitations_controller#new checks for the presence of :project_id and invokes the appropriate behavior for case 1 or 2.

+5
source

Source: https://habr.com/ru/post/1397336/


All Articles