How to merge 2 object-Collection of common programming errors

pass the ids to find in a single call like

@posts = Post.find([1, 2])

Be warned that if there is no post with ID=1 or ID=2, this will raise an error. If you dont this, use where or find_all_by_id

@posts = Post.where(id: [1, 2])
@posts = Post.find_all_by_id([1, 2])

The main difference between the 2 is that you can chain other queries with where whereas find_all_by_id already returns an array so you can’t chain queries.

Originally posted 2013-11-09 21:42:59.