В базе у меня есть такая строка
[
{"color"=>"Beige", "title"=>"Icon Shirt", "title_slug"=>"icon_shirt", "brand"=>"Dockers", "brand_slug"=>"dockers", "details"=>"The cotton Alpha Icon button-up shirt by Dockers is a casual and versatile piece that goes with just about anything, so you have one less thing to worry about.", "webid"=>10462837, "pictures"=>["https://...", "https://.."], "main_price"=>59.5, "colors_pic"=>"https://...", "sale_price"=>29.75, "precent_off"=>50, "sizes"=>"S/XL/XXL", "external_id"=>1022},
{"color"=>"White", "title"=>"Icon Shirt", "title_slug"=>"mens_slim-fit_alpha_icon_shirt", "brand"=>"Dockers", "brand_slug"=>"dockers", "details"=>"The cotton Alpha Icon button-up shirt by Dockers is a casual and versatile piece that goes with just about anything, so you have one less thing to worry about.", "webid"=>10462837, "pictures"=>[""], "main_price"=>59.5, "colors_pic"=>"", "sale_price"=>29.75, "precent_off"=>50, "sizes"=>"S/M/L/XL/XXL", "external_id"=>1143}
]
Т.е это 2 товара ( точнее 2 офера товара) в виде массива 2х хешей, я пытаюсь получить обратно это значение из базы, чтобы работать с этими данными :
@items__temp = @product.query("SELECT * FROM products WHERE id = 6161")
@items__temp.each do |item|
temp__id = item["id"]
# @items = item["full__desc"].unpack('A6Z6')
# eval '[ {}, {} ]'
@string__hash = item["full__desc"] # Это столбец с данными
@string__hash.slice(1)
@string__hash.slice(2509)
# puts @string__hash.extension[1..-1]
# revert = @string__hash.reverse
# Пробую пересобрать массив
@string__hash = @string__hash[1..@string__hash.length]
@string__hash = @string__hash.reverse[1..@string__hash.length].reverse
puts @string__hash.split("},")
@string__hash
i += 1
end
Любые действия с @string__hash как с хешом не проходят, т.к из базы приходит "string" , я пробовал преобразовать через unpack, пробовал пересобрать массив заново через регулярки ( т.е выдернуть данные и создать новые хеши), но не выходит. Я понимаю что лучшим решением было бы хранить json в базе, но удобнее было бы работать сразу с хешами. Что можно попробовать?