Reputation: 2262
I'm using devise
and devise_invitable
gems on a project management web app. I am successfully inviting new users to to the web app.
But what I need is to invite new users to a specific project and can't figure out how to do that. I need the project ID as part of the route so I can properly wire up the controller code.
Relevant routes.rb
section looks like:
devise_for :users, :controllers => { :invitations => "invitations" }
So:
users/invitation/new
works for new invitations.invitations_controller.rb
overrides default InvitationsController
I have :projects
as a resource that I'm using, e.g.
resources :projects do
resources :milestones, :task ... etc
end
(I think) I am looking to make something like this work:
users/invitation/projects/4f3423d34323/new
Upvotes: 5
Views: 1359
Reputation: 2262
Current approach is to specify the 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 I can use:
Case 1: users/invitation/new
(for inviting new user to web app)
and
Case 2: projects/:project_id/invitations/new
(for inviting new user to web app + project)
invitations_controller#new
checks for presence of :project_id
and invokes appropriate behaviour for Case 1 or 2.
Upvotes: 5