I have a model called a package with a number of attributes (package resources). I want to display the content of the package in a set of tabbed fields - with one for each selected resource.
If a resource is not involved in a project, then there won't be a tab for it displayed in the view.
I have set up the tabs so they only display if the resource is selected as true. That is done as follows:
<div class="dp-tab-1">
<ul class="dp-tab-list row" id="myTab">
<% if @project.package.has_background_ip == true %>
<li class="col-md-2 col-xs-6 active" >
<a href="#tab-content-first">
<span class="glyph-item" data-icon=""></span>
</a>
</li>
<% end %>
<% if @project.package.has_data == true %>
<li class="col-md-2 col-xs-6">
<a href="#tab-content-second">
<div class="glyph-item" data-icon=""></div>
</a>
</li>
<% end %>
<% if @project.package.has_material == true %>
<li class="col-md-2 col-xs-6">
<a href="#tab-content-third">
<div class="glyph-item" data-icon=""></div>
</a>
</li>
<% end %>
</ul>
The problem with the bit above is that the active tab is designated inside the first tab. If the first tab is not a required resource, then the next two tabs may be included (if required) but the first of them to be true will not have the designation of true.
How do I dynamically allocate 'active tab' status to the first true condition so that the tab content displays for the active tab.
<div class="dp-tab-content tab-content">
<div class="tab-pane row fade in active" id="tab-content-first">
<% if @project.package.has_background_ip == true %>
<div class="col-md-6 text-center">
<%= image_tag(@project.package.background_ip.bip_image, :class=>"wow fadeInLeft img-responsive", :alt=>"123") %>
</div>