HABTM 关系中的 Rails 角色/权限 - 管理关系

发布于 2024-11-02 00:12:37 字数 279 浏览 9 评论 0原文

我在我的应用程序中创建了下表 - 角色、权限和 Permissions_roles。角色 HABTM 权限和 HABTM 角色权限。我看过很多关于为 3 个表设置所有表/模型等并定义关系的教程,但我找不到任何关于实际维护关系的内容 -- 最佳实践是什么 -- 设置第三个控制器/一组视图?

我希望能够独立于关系创建角色/权限,即稍后进行分配 - 如果我创建新角色,我可能需要返回并为其分配现有权限(反之亦然)。

我知道有很多插件可以做这类事情,但我真的想看看我是否可以从头开始学习更多...

谢谢

I have created the following tables in my application - roles, permissions and permissions_roles. Roles HABTM permissions, and permissions HABTM roles. I have seen many tutorials on setting up all of the tables/models etc for the 3 tables and defining the relationship, but I haven't been able to find anything on actually maintaining the relationship -- What is the best practice -- set up a third controller/set of views?

I want to be able to create Roles/Permissions independently of the relationship, ie make the assignment later - If I create a new role, I may need to go back and assign existing permissions to it (or vice-versa).

I know there are plenty of plugins that do this sort of thing, but I really want to see if I can learn more by starting from the ground up...

Thanks

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

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

发布评论

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

评论(1

无所的.畏惧 2024-11-09 00:12:37

它有点过时,但应该仍然可以工作,我对代码的冗长感到不寒而栗,但这是我在 Rails 中做的第一件事之一......

http://blog.wolfman.com/articles/2006/5/20/role-based-authentication-admin-page

Its a little bit dated, but should still work, I shudder at the verbosity of the code but it was one of the first things I did in Rails...

http://blog.wolfman.com/articles/2006/5/20/role-based-authentication-admin-page

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