Skip to content

[Incorrect behavior / Issue] Attributes validation #1532

Open
@dmytro-strukov

Description

@dmytro-strukov

Ransack version: >= 4.0
Rails: >= 7.x

Possible scenario when the issue occurs:

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

What is the problem:

  • When attribute validation does not pass the end user does not know anything about it
  • Overall in Ruby in such type of cases developers use symbols because they by default have a similar behavior as constants and do not take additional memory

The method: valid?

Options to resolve:

  • Raise error or log warn message when the attribute didn't pass the validation
  • Instead of looking in an array that will take O(n) time rather use a Hash or Set that will take O(1). Rails provide also Hash With Indifferent Access that will make it possible to use symbols and strings as keys

@scarroll32 What do you think? I can implement it and cover via test cases

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