Skip to content

Why Doesn’t Ransack Support Rails Enums Properly? #1555

Open
@pekopekopekopayo

Description

@pekopekopekopayo

Is this the intended behavior?

class Lesson < ApplicationRecord
  enum :status, {
    one: 1,
    two: 2,
    three: 3
  }
  class << self
    def ransackable_attributes(auth_object = nil)
      ["status"]
    end
  end
end
Lesson.ransack({ "status_eq" => "two" }).result 
# I expected: SELECT * FROM lessons WHERE status = 2

But the actual query is:

SELECT "lessons".* FROM "lessons" WHERE "lessons"."status" = 0

I understand that defining a ransacker in the model can be used as a workaround.
That said, if this is considered a bug, I would truly appreciate any fix or guidance.
If there's any way I could contribute to resolving it, I’d be more than happy to help.

I’m not very fluent in English, so I apologize if my words sounded rude

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