我正在RubyMine
使用rails 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.
答案 0 :(得分:13)
我在@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 })
named_scope :approved, :conditions => { :approved => true }
Post.approved.all
Post.scoped(:conditions => { :approved => true }).all
击> <击> 撞击>
答案 1 :(得分:4)
以下是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
答案 2 :(得分:3)
使用Rails 3中添加的新ActiveRecord::Relation
内容。点击此处查看更多信息:http://guides.rubyonrails.org/active_record_querying.html
而不是#find
,在模型上使用#first
,#last
,#all
等,以及返回ActiveRecord :: Relation的方法,例如{{ 1}}。
#where