Kashiftufail
Kashiftufail

Reputation: 10885

How i can assign this array into another array in rails

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

Upvotes: 0

Views: 119

Answers (1)

Alexandre Abreu
Alexandre Abreu

Reputation: 1417

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.

Upvotes: 1

Related Questions