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

  • Home
  • SEARCH
  • 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 8674801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:47:36+00:00 2026-06-12T19:47:36+00:00

I have an array containing URL paths, I want to be able to search

  • 0

I have an array containing URL paths, I want to be able to search in my database in a table which one of the fields (labelled “URL”) for the URLs specified in the array.

So I have a simplified version of what I want to achieve.

urls = ["url1", "url2", "url3", "url4", ... ]
urlsInDB = []
results = Link.all
urls.each() do |url|
 if not results.where(:url=>url).blank?
   urlsInDB << url
 end
end

However I know that you cannot call “.where” on a set of results obtained by “.all”. I want to do it this way so that the database is only ever queried once not for each URL in urls as this can have length n and that would require n queries.

Any ideas?

  • 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-06-12T19:47:38+00:00Added an answer on June 12, 2026 at 7:47 pm

    In SQL, you’d do this by saying:

    SELECT * FROM links WHERE url IN ('url1', 'url2', 'url3');
    

    You can do this with ActiveRecord by saying:

    Link.where(:url => ['url1', 'url2', 'url3'])
    

    If you just want to get an array of URLs that matched, say:

    Link.select(:url).where(:url => ['url1', 'url2', 'url3']).map(&:url)
    # SQL: SELECT url FROM links WHERE url IN ('url1', 'url2', 'url3')
    # => ['url1', 'url2']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array containing a list of files. I want to sort it
I have an array containing specific times and I want when the current time
Ruby 1.8.6 I have an array containing numerical values. I want to reduce it
I have create an array containing person firstname,lastname and number which i populate in
I have an array of variables all containing text. I want to select only
I have an array containing the contents of a MySQL table. I need to
I have an Array in PHP which contains data from database. And it prints
I have an array containing much more items than just this one. This is
If I have an array containing a number of urls: ['http://www.abc.com', ..., 'http://www.xyz.com'] for
I have an array containing full paths of files. Like this: [0] => dir1/dir2/dir3/file.ext

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.