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

  • SEARCH
  • Home
  • 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 7980659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:08:35+00:00 2026-06-04T10:08:35+00:00

I am pulling a flat hash of parameters from an external API into my

  • 0

I am pulling a flat hash of parameters from an external API into my Rails app. I need to present these parameters to the user in a select field.

The hash is formatted as follows:

[["Name", "ID", "Category"]]

I’d like to present this as a grouped select. But I believe the grouped_select tag takes a hierarchical hash, not a flat hash?

Is there an easy way to restructure this hash into a structured hash? i.e.,

['CategoryA', [['Name-A1','ID-A1'],['Name-A2', 'ID-A2']]

For reference, I’m currently handling the hash in my controller like this

@hash = session["hash"].map { |h| [ h["name"], h["id"], h["category"] ] }

and in the view

<%= f.select :hash_id, @hash %>

This gives me an unordered list of options. How can I group on h["category"]?

Thanks for any pointers.

EDIT

By the way, I;ve already tried group_by as it seemed the obvious way to go. But I’m getting can't convert String into Integer. Perhaps I’m not using it correctly?

hash.group_by {|h| h["category"] }.map { |h| [ h["name"], h["id"], h["category"] ] }
  • 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-04T10:08:37+00:00Added an answer on June 4, 2026 at 10:08 am
    hash.group_by {|h| h["category"] }.map { |h| [ h[0], h[1].map{|e| [e["name"],e["id"]]} ] }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pulling in the RSS feed from Craigslist into a rails app I'm building.
I'm pulling in data from a flat file into a SQL Server 2008 table.
I'm pulling in data from an external place database that returns JSON of information
I am pulling data from a sql server and putting it into a grid
I am pulling back some data from the twitter query API, and parsing it
I am pulling a long timestamp from a database, but want to present it
Pulling from http to escape authentication(so I don't need to type password if I'm
pulling some info from a MySQL db via openquery: select * from foo where
Im pulling a text file - it will be input by user currently its
I am pulling data from one table, called analyzedCopy, and using it to over-rite

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.