If you only need an array with all identifiers, you should use pluck , since it makes the correct request, t should use any ruby. In addition, he does not need to create an instance of the hotel object for each record returned from the database. (faster).
Hotel.where(selection: 1).pluck(:id)
source share