Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4027982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:09:50+00:00 2026-05-20T11:09:50+00:00

I have a collection like this: UserLevels id blah_id blah2_id .. .. Now I

  • 0

I have a collection like this:

UserLevels
   id
   blah_id
   blah2_id
   ..
   ..

Now I want to further file this collection with all rows that have

blah2_id = 3

I don’t need to hit the database again as I already have this collection, and this collection will have maybe 5-10 rows in it anyhow at most.

What’s the best way to do this? Or what options do I have.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:09:51+00:00Added an answer on May 20, 2026 at 11:09 am

    The first option that springs to mind is Array#select (Ruby 1.9 only):

    @collection = UserLevel.all
    @filtered_collection = @collection.select { |l| l.blah2_id == 3 }
    

    Ruby’s Array class is quite powerful, and is worth investigating: http://www.ruby-doc.org/core/classes/Array.html

    In Ruby 1.8, the equivalent method is Enumerable#find_all:

    @filtered_collection = @collection.find_all { |l| l.blah2_id == 3 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of MODS records that looks like this: <modsCollection> <mods [namespaces
The situation is like this: I have an Observable Collection that has a bunch
I have a collection of country objects that look like this: class country {
I have a model with an object that contains a collection like this: namespace
I have a collection of objects that look like this: List<MyObject> objects = new
I have a variable like: Collection<Map<String, String>> allFieldValues; In this variable I have all
i have image collection @images = Image.find(:all) and displaying it like this <%@images.each do|image|%>
I have a ko.computed() function that proxies a collection like this: function ListView(query) {
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
Suppose I have a collection of files like this: echo -e apple\n cherry >>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.