find(:first) 和 find(:all) 已弃用 [英] find(:first) and find(:all) are deprecated
本文介绍了find(:first) 和 find(:all) 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将 RubyMine
与 rails 3.2.12
一起使用,并且在我的 IDE 中收到以下已弃用的警告.任何想法我该如何解决这个已弃用的警告?
I am using RubyMine
with rails 3.2.12
and I am getting following deprecated warning in my IDE. Any Idea How can I solve this deprecated warning?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2.
推荐答案
我在@keithepley 评论后更改了我的答案
I changed my answer after @keithepley comment
#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!
<打击>
您可以从这些位置
已弃用的声明
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
这篇关于find(:first) 和 find(:all) 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文