设计一个包含管理部分和面向公众的部分的 Web 应用程序。 感觉仅仅为了“索引”和“显示”而拥有一个面向公众的控制器有点多余。 我读过的所有建议都建议为管理员提供一个命名空间,这很好。 我只是想知道我是否应该有一个带有附加操作的控制器,比如“list_public”或类似的东西。
我是 Rails 新手,所以也许我什么都不关心。 我只是不喜欢将所有这些具有相同名称的控制器、视图、助手分散在我的项目目录中。
有人对此有任何见解吗? 提前致谢。
Designing a web app with a admin section and a public facing section. It feels like having a public facing controller just for "index" and "show" is a bit redundant. All the suggestions I've read suggest a namespace for admin, which is fine. I just wonder if I should have one controller with an addition action, say "list_public" or something like that.
I'm new with Rails, so maybe I'm just concerned about nothing. I just don't like the idea of having all these controllers, views, helpers with the same name scattered all over my project directories.
Anyone have any insight to this? Thanks in advance.
发布评论
评论(2)
我想说拥有两个控制器(一个公共控制器和一个管理员控制器)是最好的解决方案。
现在您可以做的是让两个控制器调用相同的方法来执行操作中的相关操作。
I would say having both controllers (one public, and one admin) is the best solution.
Now what you could do is have both the controllers call the same method that does the related actions in the actions.
正如马特所说,但您也可以这样做:
这意味着您可以只关注 Admin::MyController 的更特殊的情况,而不是重复代码。
As Matt said, but you can also do this:
This means that you can just focus on the more specialised cases for Admin::MyController rather than repeating code.