Skip to content

Instantly share code, notes, and snippets.

@mrded
Last active August 29, 2015 14:01
Show Gist options
  • Save mrded/a6814f7c45707b945c28 to your computer and use it in GitHub Desktop.
Save mrded/a6814f7c45707b945c28 to your computer and use it in GitHub Desktop.
Rails: array of IDs
# If you want to go directly to the DB
ActiveRecord::Base.connection.select_values("select id from users")
# If you already have a model
User.all(:select => :id).collect(&:id)
# In Rails 3 you can do this
User.pluck(:id)
# Rails helper
User.comment_ids
# Without DB
User.all.collect { |obj| obj.id }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment