0

Hi i come cross problem where i want to assign an array in to another array

like i have this value save in DB of a attribute of table like

      ["rogid", "soni"]

      a_array = []

after retrieving from DB i want to assign as it

      a_array =  ["rogid", "soni"]

after assign it should look like this after i display

      ["rogid", "soni"]

but when i display a_array it is like this

     ["[\"rogid\", \"soni\"]"]

how i can achive it like same as ["rogid", "soni"]

Many many thanks for help

5
  • 6
    Please show us the code as you have it now so that we know what you are doing wrong. Commented Sep 11, 2012 at 19:10
  • Looks like you convert your array to string and back to array somehow. ["rogid", "soni"].to_s.to_a => ["[\"rogid\", \"soni\"]"] Commented Sep 11, 2012 at 19:15
  • @RyanBigg when i use this <%=answer.other_software %> it write on view ["rogid", "soni"] just like string array Commented Sep 11, 2012 at 19:21
  • @RyanBigg how i assign this string array after retrieving from DB same as to another array Commented Sep 11, 2012 at 19:23
  • @RyanBigg actually <%=answer.other_software %> this code give me a string like ["rogid", "soni"] and how i can make it a string array. Thanks for your time Commented Sep 11, 2012 at 19:27

1 Answer 1

1

You could use a regex to parse the string: rogid an soni on rubular

Im getting some odd ruby behavior here so i cannot confirm this answer right now, but im pretty sure you can handle it:

REGEX

my_pattern.match(my_string).to_a will return you desired array. Also dont forget pull "[\"rogid\", \"soni\"]" from ["[\"rogid\", \"soni\"]"] before using the regex.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.