gpt4 book ai didi

ruby-on-rails - 当显示所有类别+属于当前类别的所有帖子时,哪个 Controller 应该处理请求

转载 作者:太空宇宙 更新时间:2023-11-03 16:50:55 24 4
gpt4 key购买 nike

我有一个 Post 模型,它与 Category 模型具有多对一关联。

在我正在使用的 View 中,我想在导航中显示所有类别,在内容区域中显示属于当前所选类别的所有帖子。

我应该通过“PostsController”还是“CategoriesController”路由对此网页的请求?我知道这两者在技术上都是可能的。

最佳答案

如你所说

I want to display all categories in the navigation and in the content area all posts belonging to currently selected category

我认为主页应该落在 CategoriesController

但是,如果您在点击特定类别以加载帖子后发送请求,则此请求应转到 PostsController

原因:关注<强>CRUD 在页面加载时它将加载所有 Categories 所以它是 Categories 的索引页所以这应该属于 CategoriesController

当您加载与该类别相关的所有 post 然后加载与 PostsController 更相关的 IMO 时相同。

编辑:正如您所说,您正在一个请求中加载所有数据,那么在我看来,您应该使用 CategoriesController

关于ruby-on-rails - 当显示所有类别+属于当前类别的所有帖子时,哪个 Controller 应该处理请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22260669/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com