When trying to index divs so that the accordion buttons will collapse correctly, it's indexing every first contact in each category in my json file as 0 instead of indexing every contact no matter the category consecutively.
Here's my erb file:
<% @contacts.each do |category, hash| %>
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><%= category %></h3>
</div>
<div class="panel-body">
<ul class="list-group">
<% hash.each_with_index do |contact, index| %>
<li class="list-group-item" style="border: none">
<button type="button" class="btn btn-info" data-toggle="collapse" data-parent="#accordion" data-target="#collapse<%= index %>"><%= contact['name'] %><%= index %></button>
<div id="collapse<%= index %>" class="panel-collapse collapse">
<%= contact['email'] %></br><%= contact['ext'] %>
</div>
</li>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
json file: (It's indexing the first name in each group i.e. "Manager, Team Lead" as 0. I want Rob = 0, Terry = 1, Ben = 3, and so on.
{
"Manager":[
{
"name": "Rob",
"email": "Rob@com",
"ext": "ext:"
}
],
"Team Lead":[
{
"name": "Terry",
"email": "Terry@com",
"ext": "ext"
}
],
"Unix Admins":[
{
"name": "Ben",
"email": "Benjamin@com",
"ext": "ext"
},
{
"name": "Prashant",
"email": "Prashant@com",
"ext": "ext"
},
{
"name": "Harshil
"email": "Harshil@com",
"ext": "ext"
},
{
"name": "Laxmikanth",
"email": "Laxmikanth@com",
"ext": "ext"
},
{
"name": "Mary",
"email": "Mary@com",
"ext": "ext"
}
],
"On-Call Contact":[
{
"name": "SYSTEM ADMIN UNIX",
"email": "Unix@com",
"ext": "ext"
}
]
}
.rb file:
get '/contact' do
contact = Contacts.new
@contacts = contact.getContacts
@contacts.each { |s| puts "get /contact found contact #{s.last.first['name']}" }
erb :contact