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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:06:21+00:00 2026-06-13T00:06:21+00:00

I have a YAML database with data in the following format: – product: name:

  • 0

I have a YAML database with data in the following format:

- product:
  name: Apples

- product:
  name: Grapes

How can I update it so each product is assigned to a category, then on my page I can have an unordered list the products under a category heading?

For example:

Fruit
  *Apples
  *Grapes

Vegetables
  *Tomatoes
  *Broccoli

I tried searching for an example of something like this, but couldn’t find anything. Is it possible to do something like this?

- category:
  name: fruit

  - product:
    name: Apples

  - product:
    name: Grapes

- category:
  name: vegetables

  - product:
    name: Tomatoes

  - product:
    name: Broccoli  
  • 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-13T00:06:23+00:00Added an answer on June 13, 2026 at 12:06 am

    I’d suggest two schemes, the first groups all products together:

    products:
      - name: Apple
        type: Fruit
    
      - name: Grape
        type: Fruit
    
      - name: Tomato
        type: Vegetable
    
      - name: Brocoli
        type: Vegetable
    

    The other scheme would be using on group for each type of product

    fruits:
      - name: Apple
    
      - name: Grape
    
    vegetable:
      - name: Tomato
    
      - name: Brocoli
    

    To actually display this you would just load the yaml data with something like (forgive me if this has changed… it’s been a while since I used yaml):

    require 'yaml'
    data = YAML.load_file('data.yml')
    

    data is essentially just a ruby hash so you can display whatever you like by traversing it.

    EDIT:

    If the second option is what you want. Try the following:

    require 'yaml'
    
    data = YAML.load_file('data.yml')
    data.each do |category, products|
      puts "#{category}"
      products.each do |product|
        puts "\t#{products}"
      end
    end
    

    Output should be:

    fruits
         Apple
         Grape
    vegetable
         Tomato
         Brocoli
    

    If you want to output html, then modify it to something like:

    require 'yaml'
    
    data = YAML.load_file('data.yml')
    data.each do |category, products|
      puts "#{category}"
      puts "<ul>"
      products.each do |product|
        puts "<li>#{products}</li>"
      end
      puts "</ul>"
    end
    

    You can see the differences to add the html formatting is very simple and you should be able to further modify this to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

where can i learn more abt creating database markup in yaml and data fixtures.
I have the YAML for the invoice data to go into the testing database:
Hi i have a yaml file like so --- data: - date: 2004-06-11 description:
I have the following Python 2.6 program and YAML definition (using PyYAML ): import
I have this YAML file: name: Firas dirs: [/bin/, /home/phiras/] I am using YAML::Syck
Okay, I have the following YAML file that was generated by using yaml_db for
I have written my yaml schema for the database for my Symfony+doctrine application, and
I have code that relies heavily on yaml for cross-language serialization and while working
I have a list of dict convert from yaml, but how do I merge
I have encountered what appears to be a bug with the YAML parser. Take

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.