Guest User

Untitled

a guest
Feb 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. #returns an ActiveRecord::Relation object
  2. @blogs = Blog.all
  3.  
  4. # Search for the blog within that ActiveRecord::Relation object, NOT the database
  5. @blogs.find_by(id: 1).title #do this statement but don't hit the database again
  6.  
  7. @blogs.find {|b| b.id == 1}
  8.  
  9. @blogs.detect { |b| b.id == 1 }
  10.  
  11. @blogs.where(id: 1).first.reload
Add Comment
Please, Sign In to add comment