ruby-on-rails-3 – find(:first)和find(:all)已弃用

前端之家收集整理的这篇文章主要介绍了ruby-on-rails-3 – find(:first)和find(:all)已弃用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用带有rails 3.2.12的RubyMine,我在IDE中得到了不推荐使用的警告.任何想法如何解决这个已弃用的警告?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2.

解决方法

在@keithepley评论后我改变了我的回答
#Post.find(:all,:conditions => { :approved => true })
Post.where(:approved => true).all

#Post.find(:first,:conditions => { :approved => true })
Post.where(:approved => true).first
or
post = Post.first  or post = Post.first!
or
post = Post.last   or post = Post.last!

您可以从this locations阅读更多内容

弃用声明

Post.find(:all,:conditions => { :approved => true })

更好的版本

Post.all(:conditions => { :approved => true })

最佳版本(1)

named_scope :approved,:conditions => { :approved => true }
Post.approved.all

最佳版本(2)

Post.scoped(:conditions => { :approved => true }).all

猜你在找的Ruby相关文章