Rails 4 Relation#all deprecation

后端 未结 3 520
情深已故
情深已故 2021-01-17 12:25

In my app I created a recent posts feature.

 @recentposts = Post.all(:order => \'created_at DESC\', :limit => 5)

This variable makes

3条回答
  •  旧巷少年郎
    2021-01-17 13:18

    Just write:

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

    The to_a is not explicitly necessary, as the data is lazy loaded when needed.

提交回复
热议问题