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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:12:43+00:00 2026-06-17T08:12:43+00:00

How do I split this array and store into the database? I have three

  • 0

How do I split this array and store into the database?

I have three fields in my model called Question_id, Answer_id and Phase_id.

I have a result like:

question_hash_string = "{\"5\":[\"5\",\"0\",\"\"],\"25\":[\"25\",\"1\",\"3\"]}"}

Which looks like {5:[5,0,1], 25:[25,1,3] ... }.

I want to split the array and store the results into the three fields in order Question, Answer and Phase of each set.

In my Batch table, I have three columns: question_id, answer_id and phase_id.

The first value of array[5,0,1], 5 goes to question_id, 0 to answer_id and 1 to phase_id. In the second row 25 to question_id, 1 to answer_id and 3 to phase_id.

  • 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-17T08:12:44+00:00Added an answer on June 17, 2026 at 8:12 am

    You can do this:

    hash_values = JSON.parse(question_hash_string)
    hash_values.each do |k,v|
      b = Batch.new
      b.question_id, b.answer_id, b.phase_id = v.collect(&:to_i)
      b.save!
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to split this string 主楼怎么走 into separate characters (I need an array) using
Let's say I have an array that store like this: Array ( [0] =>
I want a split a result of <= 1000 characters into an array of
I have an array with a list of objects. I want to split this
I have the following array I want to store in my database... $insData =
I am trying to split this css file into different blocks. Everything matching /*@-
I have text file with some text information and i need to split this
I have a string stack+ovrflow*newyork; i have to split this stack,overflow,newyork any idea??
I have a MongoMapper model and am trying to convert a comma-delimited string into
I'm opening a new thread based on this how to store an array in

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.