Ad

Using Bootstrap's Collapse With Rails 4

I'm trying to display a list of chapters with some sample text.

Here's what I'm working with:

      <div class="col-md-3 col-md-4-border">
        <% @book.chapters.each do |chapter| %>
        <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
      <div class="panel panel-default">
        <div class="panel-heading" role="tab" id="headingOne">
          <h4 class="panel-title">
            <a role="button" data-toggle="collapse" data-parent="#accordion" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="collapseExample" aria-expanded="true" aria-controls="collapseExample">
              <%= chapter.title %>
            </a>
          </h4>
        </div>
        <div id="collapseExample" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            testing
          </div>
        </div>
      </div>
    </div>
      <% end %>
    </div>

The above snippet shows a list of chapters in my view but fails to toggle.

Here is the source for Bootstrap's Collapse function: http://getbootstrap.com/javascript/#collapse

Ad

Answer

Figured this out. I needed to add <%= chapter.id %> to the href and other applicable areas.

Ad
source: stackoverflow.com
Ad