Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from 1dolinski/user.rb
Last active December 19, 2015 04:28
Show Gist options
  • Save tbuehlmann/5897229 to your computer and use it in GitHub Desktop.
Save tbuehlmann/5897229 to your computer and use it in GitHub Desktop.
# get all users
@users = User.all
# get users from given ids
ids = [2, 1, 3, 4, 5]
@users = User.find(ids)
[17] pry(main)> ids = User.all.map(&:id)
=> [2, 1, 3, 4, 5]
[19] pry(main)> ids.each do |id|
[19] pry(main)* @users = User.where(id: id) rescue User.where(id: id)
[19] pry(main)* end
=> [2, 1, 3, 4, 5]
Why doesn't this return all of the instances of User?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment