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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:23:20+00:00 2026-06-14T07:23:20+00:00

I have a bit multidimensional array like this one: [[2, 1], [751, 159], [793,

  • 0

I have a bit multidimensional array like this one:

[[2, 1], [751, 159], [793, 195], [978, 527], [938, 783], [977, 881], [713, 592, 101], [337, 248, 143], [444, 647, 196], [913, 763, 211], [752, 746, 225], [862, 878, 373], [876, 900, 597], [719, 904, 236, 11], [448, 836, 883, 59], [486, 723, 241, 150], [864, 611, 619, 167], [558, 796, 707, 353], [915, 683, 738, 534], [641, 777, 892, 107, 78], [264, 310, 161, 574, 114], [549, 849, 596, 181, 160], [633, 471, 497, 438, 262], [351, 485, 544, 772, 348], [890, 941, 572, 418, 374], [776, 972, 1001, 729, 379], [595, 898, 989, 771, 454], [84, 514, 914, 571, 442, 19], [335, 97, 689, 314, 879, 20], [869, 828, 802, 859, 553, 34], [298, 134, 564, 614, 411, 62], [175, 579, 490, 399, 479, 72], [382, 830, 215, 691, 624, 85], [922, 840, 657, 917, 436, 95]] 

As you can see, each sub array has between 2 and 6 values.

I have a model called “Sub” with db columns “sub1”, “sub2”, “sub3”, “sub4”, “sub5”, “sub6”. (values for sub3-6 would be null if the sub array only had 2 values)

What is the proper way to save each sub array to a db row?

I have tried this:
@m = [the big array I mentioned above]

      @m.each do |t|
        Pair.create(:sub1 => t[0], :sub2 => t[1], :sub3 => t[2], :sub4 => t[3], :sub5 => t[4], :sub6 => t[5])
      end

But for some reason that creates a table that does this: (sample of “sub1” column)

2
2
751
2
751
793
2
751
793
978
2
751
793
978
938

See what’s happening there? It repeats each but adds one more row each time.

Here’s my model:

class Pair < ActiveRecord::Base
  attr_accessible :id, :sub1, :sub2, :sub3, :sub4, :sub5, :sub6
end

UPDATE: I figured out the issue… I had the create method in the wrong part of a script and that was causing it to run several times in a row in a weird way. Thanks everyone!

  • 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-14T07:23:22+00:00Added an answer on June 14, 2026 at 7:23 am

    One way would be to serialize the column. See here: http://api.rubyonrails.org/classes/ActiveRecord/Base.html#method-c-serialize at the Saving arrays, hashes, and other non-mappable objects in text columns section.

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

Sidebar

Related Questions

Im looking for a bit tricky thing :) I have a multidimensional array like:
I'm have a little bit of trouble storing and accessing a multidimensional array from
I have used bit field with a structure like this, struct { unsigned int
i have this bit of html. (Link at bottom) Its output of php code
I have an single-dimensional array of PHP objects. Each object has two attributes, one
I have this bit of code def build_tree_base(blocks, x, y, z): indicies = [
I have a string which represents a multidimensional array in the format: [[A, a],
I have a signal in VHDL declared like this : signal Temp_Key : std_logic_vector(79
I have a class with operator() like this: struct S { int operator()(int a,
Say i have a multidimensional array. For example: 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.