Devise Invitable 显示受邀用户
Devise Invitable display invited users
我正在使用 devise_invitable gem 和 Devise
,但我不知道如何显示所有受邀用户的列表。 我想列出状态为 accepted/pending 的所有受邀用户。
我已经制作了一个自定义的 Invitations 控制器(根据官方文档),它继承自 Devise 的控制器,其中我有一个 super 语句,因此它不会更改功能,而是在 super 下面添加一些。我搜索了与此相关的问题,发现很少,但它们使用了完全不同且不相关的方法。感谢任何输入~
例如,尝试从 invitations/new 视图访问@users 会引发 undefined method 'each'
.
如果您有 invitations_controller
,您只需添加:
def index
@users = User.all
end
您不需要继承 Devise,只需继承 ApplicationController
。您将能够访问 @users
变量,现在如果您想将结果分成两个单独的数组,则:
def index
@pending_users = User.where(invitation_accepted_at: nil)
@accepted_users = User.where.not(invitation_accepted_at: nil)
end
并且您的视图可以访问 @pending_users
以及 @accepted_users
我正在使用 devise_invitable gem 和 Devise
,但我不知道如何显示所有受邀用户的列表。 我想列出状态为 accepted/pending 的所有受邀用户。
我已经制作了一个自定义的 Invitations 控制器(根据官方文档),它继承自 Devise 的控制器,其中我有一个 super 语句,因此它不会更改功能,而是在 super 下面添加一些。我搜索了与此相关的问题,发现很少,但它们使用了完全不同且不相关的方法。感谢任何输入~
例如,尝试从 invitations/new 视图访问@users 会引发 undefined method 'each'
.
如果您有 invitations_controller
,您只需添加:
def index
@users = User.all
end
您不需要继承 Devise,只需继承 ApplicationController
。您将能够访问 @users
变量,现在如果您想将结果分成两个单独的数组,则:
def index
@pending_users = User.where(invitation_accepted_at: nil)
@accepted_users = User.where.not(invitation_accepted_at: nil)
end
并且您的视图可以访问 @pending_users
以及 @accepted_users