带角色的 Rails 路由,如何设置?

发布于 2024-10-19 15:27:08 字数 466 浏览 4 评论 0原文

这更多的是一个概念性问题...

我正在开始开发一个具有几个角色(例如员工、经理、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 技术交流群。

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

发布评论

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

评论(1

维持三分热 2024-10-26 15:27:08

你是对的,在这种情况下将不同的角色分组到相同的视图/控制器中没有多大意义,因为视图都是不同的。即使您稍后需要共享视图,也可以只渲染相同的布局。

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.

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