adding the id to the hash
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| %>
开发者_C百科 <%= 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
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.
精彩评论