Rails:角色/管理员

发布于 2024-11-17 20:35:00 字数 316 浏览 4 评论 0原文

前言 我是 Rails 的新手编程。正在开发我的第一个 Rails 应用程序——我通过omniauth 进行了身份验证,并为用户设计了一个简单的文章提交。

我想做两件事:

  1. 如果用户不是特定角色, 将它们重新路由到另一个页面。

  2. 如果首选项仅限“离线” 允许管理员查看站点。

我还没有创建一个偏好表——寻找建议。 :)

设置简单角色的最佳方法是什么? 如果用户不是管理员并且网站处于“离线”状态,那么重定向用户的最简单方法是什么?

Prefface
I'm new to rails & programming. Working on my first rails app--I have authentication with omniauth and devise and a simple article submission working for users.

I want to do two things:

  1. If a user isn't a specific role,
    reroute them to another page.

  2. If a preference is 'offline' only
    allow admins to view the site.

I have yet to create a prefferences table--looking for suggestions. :)

What's the best way to set up simple roles?
What's the easiest way to redirect users if they're not admin and if the site is 'offline'?

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

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

发布评论

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

评论(1

最冷一天 2024-11-24 20:35:00

我目前正在使用 CanCan 对我当前的项目进行基于角色的授权。我发现它非常有效,包括能够完成您正在寻找的两项任务。还有文档!哦,文档。如果所有 gem 作者都写出像 CanCan 那样的文档,我相信这会带来世界和平。

作为一个额外的好处,因为它是由 Ryan Bates 编写的,所以它有一个 RailsCast 已为其录制。

I'm currently using CanCan for role-based authorization on my current project. I've found it works great including the ability to do both of what you're looking for. And the documentation! Oh, the documentation. If all gem authors wrote documentation like CanCan's, I do believe it would bring about world peace.

And as an added bonus, because it was written by Ryan Bates, it has a RailsCast already recorded for it.

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