带角色的 Rails 路由,如何设置?
这更多的是一个概念性问题...
我正在开始开发一个具有几个角色(例如员工、经理、store_manager)的应用程序。每个角色将以不同的方式查看/编辑/销毁。当经理编辑员工时,视图将与 store_manager 编辑时非常不同。
我的想法是用该角色为许多模型命名。喜欢:
namespace :store_manger do
resources :users
resources :widgets
end
namespace :manager do
resources :users
resources :widgets
end
这似乎是比创建所有 if 更干净的方法? :update, @article 遍布控制器和视图。
那么,我的想法是否步入正轨?
使用这种方法有什么我需要注意的陷阱吗?
或者,有更好的方法来组织这个吗?
This is more of a conceptual question...
I'm starting on an app that will have a few roles (e.g. employee, manager, store_manager). Each role will view/edit/destroy in different ways from each other. When a manager is editing an employee the view will be very different than when a store_manager is editing.
My thinking was to namespace many of the models with the role. Like:
namespace :store_manger do
resources :users
resources :widgets
end
namespace :manager do
resources :users
resources :widgets
end
This seems to be a much cleaner method than creating all the if can? :update, @article all over the controllers and views.
So, is my thinking on track?
Are there any pitfalls to using this method that I need to be aware of?
Or, is there a better way to organize this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,在这种情况下将不同的角色分组到相同的视图/控制器中没有多大意义,因为视图都是不同的。即使您稍后需要共享视图,也可以只渲染相同的布局。
You're correct, grouping different roles into the same view/controllers doesn't make much sense in this case since the views are all different. Even if you need to share views later on, you can just render the same layout.