ruby-on-railsactiveadminformtastic

Activeadmin: Adding partial to end of index as block


I'm trying to add a modal to my index page by rendering the modal partial onto the page. Whenever I add the partial, it adds it 30 times, 1 for each record displaying. This only occurs when I do index as: :block.

Here's my code:

  index as: :block, download_links: true do |ticket|
    div :for => ticket, class: "ticket #{ticket.current_state}" do
      resource_selection_cell(ticket) if authorized?(:export, ticket)
      render ticket, actions: true
    end
    render partial: 'resolve_modal'
  end

_resolve_modal.html.erb

<!-- Modal -->
<div class="modal fade" id="resolve-modal" tabindex="-1" role="dialog" aria-labelledby="resolve-modal" aria-hidden="true">
  <div class="modal-dialog modal-md">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title" id="resolve-modal-title">Resolve</h4>
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
      </div>
        <div class="modal-body text-left">
          <div class="text-center alert status"></div>
          <div class="form-group">
            <label for="resolution">Resolution</label>
            <textarea class="form-control" id="resolution" rows="3"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary" id="resolve-button">Resolve</button>
        </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

Again, it's showing the modal 30 times. I only want it be in the source code 1 time. Can anyone help?


Solution

  • One way you could do this is by defining your own custom index, subclassing ActiveAdmin::Views::IndexAsBlock and adding your modal to the build method after it iterates over the collection.