如何嵌套devise_invitable路由邀请用户到具体的项目 [英] How to nest devise_invitable route to invite user to specific project
问题描述
问题
我正在使用 devise
和 devise_invitable
项目管理Web应用程序的宝石。我成功地邀请新用户访问网络应用程序。
但是我需要的是邀请新用户到特定项目并且无法确定如何做到这一点。我需要项目ID作为路由的一部分,以便正确连接控制器代码。
上下文
相关 routes.rb
部分看起来像:
devise_for:users,:controllers => {:invitations => 邀请}
所以:
-
users / invitation / new
适用于新的邀请。 - 我自己的
invitations_controller .rb
覆盖默认值InvitationsController
-
我有
:projects
作为我使用的资源,例如resources:projects do
resources:里程碑,任务...等
结束
$ b $ (我想)我正在寻找这样的工作:
users / invitation / projects / 4f3423d34323 /新
目前的方法是使用 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
这意味着我可以使用:
案例1: users / invitation / new
(邀请新用户到网络应用程序)
和
案例2: projects /:project_id / invitations / new
(用于邀请新用户上网app + project)
invitations_controller#new
检查的存在:project_id
并为案例1或2调用适当的行为。
Problem
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.
Context
Relevant routes.rb
section looks like:
devise_for :users, :controllers => { :invitations => "invitations" }
So:
users/invitation/new
works for new invitations.- My own
invitations_controller.rb
overrides defaultInvitationsController
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
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.
这篇关于如何嵌套devise_invitable路由邀请用户到具体的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!