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 6373053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:18:58+00:00 2026-05-25T01:18:58+00:00

I have two arrays and I’m trying to intersect them so I can run

  • 0

I have two arrays and I’m trying to intersect them so I can run a scope, my rails code looks like:

def index 
    @lists = current_user.lists
    @tasks = @lists.collect{|list| list.tasks}
    @search_tasks = Task.search(params[:search])
    @user_tasks = (@tasks & @search_tasks).now_high
end

In my browser I’m getting the following error:

undefined method `now_high’ for []:Array

So here’s what my scope looks like:

scope :now_high, lambda { where("due_date < ? AND importance = ? AND complete = ?", Date.today + 2.days, 'high', false) }

This scope works when I’m say, doing it just on Task.now_high – the problem I think is my intersect of the two arrays, and I don’t know why it’s coming up empty everytime.

In the console:

current_user = User.first
 => #<User id: 1, name:...
@lists = current_user.lists
 => [#<List id: 1, name: "Working on sharing lists"... #gets the lists that belong to the user
@tasks = @lists.collect{|list| list.tasks}
 => [[#<Task id: 1, name: "Add create permissions to 'share'",... #gets a collection of all the tasks on the user's lists.
@search_tasks = Task.all
 => [#<Task id: 1, name: "Add create permissions to 'share'"... #simulating a blank search, we have multiple records in common
ruby-1.9.2-p0 > @tasks & @search_tasks
 => [] #why is this empty?

Basically, I could conditionally have it run my scopes only if the array intersect isn’t empty. I don’t know why though it’s coming up empty no matter what?

  • 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-25T01:18:58+00:00Added an answer on May 25, 2026 at 1:18 am

    Your @tasks looks like an array of arrays. Try to flatten it before intersection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays, The $first has 5000 arrays inside it and looks like:
I have two arrays with time values in them in this format. 00:00:00 which
I have two arrays of values like X,Y,Z and 1,2 There is a table
I have two arrays like this: $array1 = [ [10, 'Some Name..'], [11, 'Some
I have two arrays of values that I would like to combine - but
I have two arrays which I'm trying to merge based on the date of
I have two arrays of strings that I would like to compare for equality:
I have two Arrays of strings, and I would like to find the set
I have two arrays they look like $a1 = array( array('num' => 1, 'name'
I have two arrays that both look like this: Array ( [0] => Array

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.