explaingit

activerecord-hackery/ransack

5,853RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Ransack adds search and filter functionality to Ruby on Rails apps using your existing database, no Elasticsearch or separate search service needed.

Mindmap

mindmap
  root((ransack))
    What it does
      Search records
      Filter results
      Sort columns
    Tech
      Ruby
      Rails
      ActiveRecord
    Use Cases
      Product search
      Admin tables
      i18n labels
    Setup
      Single Gemfile line
      No extra services
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a search bar to a Rails product listing that filters by name, price, or category without external search infrastructure.

USE CASE 2

Build a sortable, filterable admin table in a Ruby on Rails app with a single gem install.

USE CASE 3

Add multi-language search form labels to a Rails app that serves users in multiple languages.

Tech stack

RubyRailsActiveRecord

Getting it running

Difficulty · easy Time to first run · 30min
Open source project, specific license terms not stated in the explanation.

In plain English

Ransack is a Ruby gem that adds search functionality to Rails web applications. If you are building a website with Ruby on Rails and want users to be able to filter or search through records in your database, such as a product list or an admin table, Ransack provides a straightforward way to do that using standard Ruby code and HTML templates. The main advantage Ransack advertises is that it works without any additional services. Options like Elasticsearch or Algolia require running separate infrastructure and learning their own query languages. Ransack works directly against the existing database through Rails's built-in database layer, so there is nothing extra to install or pay for beyond adding the gem to your project. Installation is a single line in the Gemfile. The gem supports current versions of Rails (7.2, 8.0, and 8.1 are listed) running on Ruby 3.1 and later. There is an extensive documentation site for the project, and a quick-start cheat sheet is linked in the README for developers who want to get something working quickly. Ransack also supports internationalization, meaning search labels and messages can be translated for applications that serve users in multiple languages. Questions and help are handled through Stack Overflow and GitHub Discussions rather than the issue tracker, which is reserved for confirmed bugs. The project is open source and funded through Open Collective for ongoing maintenance.

Copy-paste prompts

Prompt 1
I'm using the Ransack gem in my Rails 8 app. Write a controller action and view partial to search products by name and filter by price range.
Prompt 2
Show me how to add multi-column sorting with Ransack to a Rails index view using link_to sort helpers.
Prompt 3
How do I set up a Ransack search form on a Rails admin table for the User model with email and created_at date range filters?
Prompt 4
Using Ransack in Rails, how do I translate search predicate labels into Spanish for an internationalized application?
Open on GitHub → Explain another repo

← activerecord-hackery on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.