Find(:first) and find(:all) are deprecated

ruby-on-rails-3ruby-on-rails-3.1ruby-on-rails-3.2

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.

Best Answer

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!

You can read more from this locations

deprecated statement

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

better version

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

best version (1)

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

best version (2)

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