HABTM 关系中的 Rails 角色/权限 - 管理关系
我在我的应用程序中创建了下表 - 角色、权限和 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它有点过时,但应该仍然可以工作,我对代码的冗长感到不寒而栗,但这是我在 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