0

I have a categories model.

attr_accessible :name, :parent, :tags, :active, :image

Sample data will be something like

"Bakery",null,"bakehouse, baker, bakeries, bakers, bakery, bakeshop, biscuit factory, boulangerie,  bread bakery, bread, cake bakery, cake topper, cake toppers, cake, cakes, confectionery, cook shop, pastry kitchen, pastry shop, pastry, patisserie, wedding cake", 1, null
"Beauty & Makeup",null,"makeup, ", 1, null

Doing @categories = Category.all gives me all categories with all the fields, now I want to create an array with the tags and the category name. The array data should be like

[["Bakery", "bakehouse"]
["Bakery", "baker"]
["Bakery", "bakeries"]
["Bakery", "bakers"]
["Bakery", "bakery"]
.....
["Beauty & Makeup", "makeup"]]

how can this be done?

1 Answer 1

2

@categories.map {|cat| cat.tags.split(/, /).map {|tag| [cat.name, tag]}} should do the trick.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.