我正在使用RubyMine
withrails 3.2.12
并且在我的 IDE 中收到了已弃用的警告。任何想法如何解决这个已弃用的警告?
find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2.
我正在使用RubyMine
withrails 3.2.12
并且在我的 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!
您可以从此位置阅读更多信息
Post.find(:all, :conditions => { :approved => true })
Post.all(:conditions => { :approved => true })
named_scope :approved, :conditions => { :approved => true }
Post.approved.all
Post.scoped(:conditions => { :approved => true }).all
这是 Rails 3-4 的做法:
Post.where(approved: true) # All accepted posts
Post.find_by_approved(true) # The first accepted post
# Or Post.find_by(approved: true)
# Or Post.where(approved: true).first
Post.first
Post.last
Post.all
使用 Rails 3 中添加的新ActiveRecord::Relation
内容。在此处查找更多信息:http: //guides.rubyonrails.org/active_record_querying.html
而不是在您的模型上#find
使用#first
, #last
,#all
等,以及返回 ActiveRecord::Relation 的方法,例如#where
.
#User.find(:first)
User.first
#User.find(:all, :conditions => {:foo => true})
User.where(:foo => true).all