在模型中运行“paginate”方法是一种常见的做法吗?
我正在使用 Ruby on Rails 3.1,我想使用 WillPaginate gem 实现分页。为了将业务逻辑保留在模型中,我想知道在模型中运行 paginate
方法(与 WillPaginate gem 相关)是否是一种常见做法。
这是常见做法还是不常见?
I am using Ruby on Rails 3.1 and I would like to implement pagination using the WillPaginate gem. In order to keep the business logic in models I would like to know if it's a common practice to run the paginate
method (related to the WillPaginate gem) inside a model.
Is this common practice or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,不是
分页调用不应该属于模型,因为它与表示严格相关。如果您正在编写自己的分页逻辑,则分页的实现可以在模型中,但对分页的调用应该在控制器中。
No it is not
Pagination calls should not belong in the model because it is strictly related to presentation. The implementation of the pagination could be in the model if you are writing your own pagination logic, but the calls to pagination should be in the controller.
我通常将分页逻辑放置在页面的控制器操作中。任何复杂到名副其实的业务逻辑都应该存在于从那里调用的模型方法中。
I generally place pagination logic in the controller action for the page. Any business logic complex enough to be worth the name should live in a model method that gets called from there.