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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:42:25+00:00 2026-05-25T06:42:25+00:00

I have an active record set corresponding to some records and I want to

  • 0

I have an active record set corresponding to some records and I want to pull particular members by index in the collection from this result (i.e. I want the 2nd, 4th and 5th record)

While this works fine:

random_members  = club.users[1,3,5]

This does not:

selected_indices = [1,3,5]
random_members = club.users(selected_indices)

I need the second method since the indices I’m using are generated.

In the first case Ruby is clearly taking applying the indices to the collection but in the second it’s trying to use the array as a method argument. This is more of a Ruby question than a rails question however I have no idea what operator to use apply the array to the collection rather than calling it as a method.

NB The indices are the positions of the members in the active record set and not the ID of the actual members.

  • 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-25T06:42:25+00:00Added an answer on May 25, 2026 at 6:42 am

    Try this:

    selected_indices = [1,3,5]
    random_members = club.users[*selected_indices]
    

    * is called the splat operator and allows you to use the contents of an array as parameters. Think of it as the contents of the array without the [].

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

Sidebar

Related Questions

Say you have an Active Record model which contains a set of records: id
I have a question concerning active record association, referring to this part of the
I have a non-rails application that I want to use rails active-record migrations with.
I have written a VBScript to extract data from Active Directory into a record
How would I use active record in this case: I have two tables: Users,
I have: function check_if_loggedin(){ #get user session id from db. $sess = $this->session->userdata('session_id'); #set
I have a two models set up like this: class User < ActiveRecord::Base #
I have a standard active record model with an attributes that is required: class
Possible Duplicate: Error loading Active Record gem with sinatra app using RVM I have
I'm tinkering with CodeIgniter and have come across Active Records for the first time.

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.