Devise:允许管理员编辑其他用户 - Rails

发布于 2024-10-30 22:33:03 字数 377 浏览 1 评论 0原文

我试图允许管理员用户在 Devise 中编辑其他用户,但是当我尝试访问另一个用户的编辑页面(例如 /users/1/edit)时,我收到以下消息:

Unknown action

Could not find devise mapping for path "/users/1/edit"

唯一的路径似乎work是/users/edit,显示当前用户的编辑页面。

在我的路线文件中,我有:

devise_for :users, :controllers  => { :registrations => 'users' }
resources :users

有什么想法吗?谢谢!

I'm trying to allow an admin user to edit other users in Devise, but when I try to access an edit page for another user (e.g. /users/1/edit), I get the following message:

Unknown action

Could not find devise mapping for path "/users/1/edit"

The only path that seems to work is /users/edit, which shows the edit page for the current user.

In my routes file I have:

devise_for :users, :controllers  => { :registrations => 'users' }
resources :users

Any ideas? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请你别敷衍 2024-11-06 22:33:03

我也必须这样做,而且它目前还没有内置到设备中。由于投票最多的答案有一个死链接,我想我应该在这里发布我的解决方案。

您需要创建一个 UsersController 并自行构建表单和控制器,但是您还需要隔离设计设置的 UsersController。为此,请在 routes.rb 文件中将 devise_for :users 调用修改为

devise_for :users, :path_prefix => 'd' # routes for devise modules on User

resources :users # custom admin-type CRUD for users

这会将所有默认的 devise-handled 路由更改为 /d/users/..并让您拥有 /users/... 路径,让您以管理员身份管理用户。

Devise 还在其 wiki 中解决了这个问题

I've had to do this as well, and it's not currently built into devise. Since the answer most upvoted has a dead link, I thought I'd post my solution here.

You need to create a UsersController and built out your forms and controller on your own, but then you also need to isolate the UsersController that devise sets up. To do this, in your routes.rb file, modify your devise_for :users call to

devise_for :users, :path_prefix => 'd' # routes for devise modules on User

resources :users # custom admin-type CRUD for users

This will change all your default devise-handled routes to /d/users/... and let you have the /users/... path to let you manage users as an admin.

Devise also addresses this in their wiki.

寻梦旅人 2024-11-06 22:33:03

Devise 非常适合用户身份验证,但它内置对管理用户的支持。所以你必须自己构建它。

这是 如何执行此操作的示例。这个例子已经有几个月了,但它应该为您指明正确的方向。

Devise is great for user authentication but it does not come with built in support for managing users. So you'll have to build that yourself.

Here's an example of how to do it. The example is a few months old but it should point you in the right direction.

等你爱我 2024-11-06 22:33:03

我已经完成了你想做的事情,而且你的路线看起来是正确的。

您还需要创建一个 UsersController 来处理您想要对用户执行的所有 CRUD 操作。这与 Devise 是分开的。

当您的 UsersController 存在时,如果 current_user 不是管理员,则只能通过重定向(可能在 before 过滤器中)允许管理员用户访问特定操作。

I've done what you're trying to do, and your routes look right.

You need to also create a UsersController that handles all of the CRUD actions you want to perform on users. This is separate from Devise.

When your UsersController is there, you can only allow admin users access to particular actions by redirecting (perhaps in a before filter) if the current_user is not an admin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文