Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 24, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original issue description:

When using the ransackable_attributes method in ActiveRecord, passing an array of symbols causes the search conditions for the corresponding attributes to be ignored. However, passing an array of strings works as expected.

Steps to Reproduce

1: Create a migration for a users table with a name column:

class CreateUsers < ActiveRecord::Migration[7.1]
  def change
    create_table :users do |t|
      t.string :name

      t.timestamps
    end
  end
end

2: Define the User model with ransackable_attributes returning a symbol array:

class User < ApplicationRecord
  def self.ransackable_attributes(auth_object = nil)
    [:name]
  end
end

3: Attempt to perform a Ransack query with a condition on the name attribute:

User.ransack(name_cont: "hoge").result.to_sql

Actual Behavior

The generated SQL query ignores the condition for name:

SELECT "users".* FROM "users"

I expected SELECT "users".* FROM "users" WHERE "users"."name" LIKE '%hoge%'

===

The code below returned the expected results:

class User < ApplicationRecord
  def self.ransackable_attributes(auth_object = nil)
    ["name"]
  end
end

===
Ruby version: 3.3.6
Rails version: 7.2.2
ransack version: 4.2.1

Fixes #1538


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug?: ransackable_attributes Fails with Symbol Array
2 participants