BulkActionable Concern

Bulk selection that survives pagination

In many Rails apps, users need to select records across several paginated pages (for example to delete, archive or export them), but the selection is lost as soon as you move to the next page or change filters.

BulkActionable solves this by storing selected IDs in cache, scoped to the current session and controller. Users can freely navigate pages and contexts while keeping their bulk selection intact until an action is performed.

  • Keep selections across paginated lists and filter changes
  • Separate selections per resource and optional groups
  • Stimulus controller for a smooth, modern UX
  • Ready-to-use REST endpoints and controller helpers

Usage Example

class PeopleController < ApplicationController
  include BulkActionable

  private

  def bulk_action_scope
    Person.all
  end

  def bulk_action_id_param
    :id
  end
end
# config/routes.rb
Rails.application.routes.draw do
  concern :bulk_actionable do
    post :bulk_action_check, on: :collection
    post :bulk_action_uncheck, on: :collection
    post :bulk_action_check_all, on: :collection
    post :bulk_action_uncheck_all, on: :collection
  end

  resources :people, concerns: :bulk_actionable do
    delete :bulk_destroy, on: :collection
  end
end
<div
  data-controller="bulk-actionable"
  data-bulk-actionable-controller-path-value="<%= people_path %>"
  data-bulk-actionable-total-items-value="<%= bulk_action_total_items %>"
  data-bulk-actionable-selected-items-value="<%= bulk_action_item_ids.to_a.to_json %>">

  <input
    type="checkbox"
    data-bulk-actionable-target="mainCheckbox"
    data-action="click->bulk-actionable#toggleMainCheckbox">

  <div data-bulk-actionable-target="showWhenSelected">
    <%= button_to bulk_destroy_people_path, method: :delete, 
          class: "btn btn-danger" do %>
      Delete Selected
    <% end %>
  </div>

  <% @people.each do |person| %>
    <input
      type="checkbox"
      data-bulk-actionable-target="itemCheckbox"
      data-id="<%= person.id %>"
      data-action="click->bulk-actionable#toggleItemCheckbox">
  <% end %>
</div>
See more in the README.

Person Information

Georgina Shanahan

Birth Date: 2007-06-06

Contacts
  • Email: jewell@erdman.example
  • Phone: 980.703.1715
Hobbies
  • Crocheting
  • Sand art
  • Genealogy
  • Flying
  • Archery
  • Tai chi
  • Lapidary
  • Glassblowing
  • Rafting
  • Digital arts