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

I use RubyMine with rails 3.2.12 and I get the following deprecated warning in my IDE. Any idea How can I resolve this obsolete warning?

 find(:first) and find(:all) are deprecated in favour of first and all methods. Support will be removed from rails 3.2. 
+6
source share
3 answers

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 learn more from these locations.

outdated operator

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

best 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 

Strike>

+12
source

Here is the Rails 3-4 path:

 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 
+4
source

Use the new ActiveRecord::Relation material added in Rails 3. Find more information here: http://guides.rubyonrails.org/active_record_querying.html

Instead of #find use #first , #last , #all , etc. on your model and methods that return ActiveRecord :: Relation, for example #where .

 #User.find(:first) User.first #User.find(:all, :conditions => {:foo => true}) User.where(:foo => true).all 
+3
source

All Articles