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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:02:48+00:00 2026-05-17T17:02:48+00:00

Ok so i am creating an hash and i need to add the id

  • 0

Ok so i am creating an hash and i need to add the id to the hash..here is my code

h = Hash.new {|h1, k1| h1[k1] = Hash.new{|h2, k2| h2[k2] = []}}
@result, today = [ h, h.dup], Date.today

Request.find_all_by_artist("Metallica", :select => "DISTINCT venue, showdate, LOWER(song) AS song, id").each do |req|
 # need to insert the req.id in the hash somewhere 
  idx = req.showdate < today ? 0 : 1
  @result[idx][req.venue][req.showdate] << req.song.titlecase
end

any suggestions on how to do this

here is my loop in the view

<% @result.each do |venue, date| %>

<li>
    <a href="#"><%= venue %></a>
            <% date.each do |key, song| %>
            <%= key %>
            <ul class="acitem">
                <% puts key.inspect %>
                <% puts song.inspect %>

                    <% songs.each do |each_song, count| %>
                    <li><%= each_song %> <%= each_song %></li>
                <% end %><% end %>
    </ul>
</li>
<% end %>

i need to have the id of every request as well….any ideas

  • 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-05-17T17:02:48+00:00Added an answer on May 17, 2026 at 5:02 pm

    If you push in the whole record and not just the title you will have access to this information when iterating over the song listing.

    @result[idx][req.venue][req.showdate] << req
    

    You can then use this as you would normally in your view:

    <% songs_requests.each do |song_request, count| %>
      <li id="song_<%= song_request.id %>"><%= song_request.song.titlecase %></li>
    <% end %>
    

    The view you’ve pasted and the structure defined in the controller don’t seem to match up completely so I’ve tried to paint the general picture here.

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

Sidebar

Related Questions

I am creating a metrics hash using the following: @metrics = Hash.new ... @metrics[:users][:year][:male]
I am working with a ruby hash that contains key/value pairs for creating a
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
I want to create a hash that combines the creating user's user_id + the
I have a problem with the creation of a hash of arrays. I need
I'm creating a hash that will eventually be dumped on disk in YAML, but
I need to see if a hash is included in another hash in a
I need some advice on creating a thumbnail cache for amazon s3. I need
So I have a for loop thats creating a hash or array depending on
I need help creating a multidimensional HashMap or Hashtable in JSP. Why I do

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.