ruby-on-rails – Rails 4关系#全部弃用

在我的应用程序中,我创建了一个最近的帖子功能.
@recentposts = Post.all(:order => 'created_at DESC',:limit => 5)

这个变量有些麻烦.当我运行测试我有以下错误:

DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation,you can call #load (e.g. Post.where(published: true).load). If you want to get an array of records from a relation,you can call #to_a (e.g. Post.where(published: true).to_a). (called from show at /home/mateusz/rails4/Bloggers/app/controllers/users_controller.rb:18)

我是Google上的seraching解决方案,但我没有找到它

解决方法

只写:
@recentposts = Post.order('created_at DESC').limit(5)

to_a没有明确的必要,因为数据在需要时被延迟加载.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...