Skip to content

Custom Predicate generates extra quote #1553

Open
@talalong

Description

@talalong

I have this Ransack configuration long time ago.

Ransack.configure do |config|
  config.add_predicate 'in_list',
    arel_predicate: 'in',
    formatter: ->(v) { v&.split(';').join("','") }
end

Calling:

Table.ransack(column_in_list: 'test;othertest').result.to_sql

Expected

WHERE table.column IN ('test', 'othertest')

Actual

WHERE table.column IN ('test'',''othertest')

There is an extra single quote added by Ransack or ActiveRecord when building the query. This breaks the SQL syntax.
What I can confirm is, it worked before.

Environment

Rails: 7.x
Ransack: 4.x
Ruby: 3.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions