Rails 4 Relation#all deprecation -


in app created recent posts feature.

 @recentposts = post.all(:order => 'created_at desc', :limit => 5) 

this variable makes trouble. when run tests have following error:

deprecation warning: relation#all deprecated. if want eager-load relation, can call #load (e.g. post.where(published: true).load). if want array of records relation, can call #to_a (e.g. post.where(published: true).to_a). (called show @ /home/mateusz/rails4/bloggers/app/controllers/users_controller.rb:18)

i seraching solution on google don't find it...

just write:

@recentposts = post.order('created_at desc').limit(5) 

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


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -