validates_overlap
validates_overlap copied to clipboard
scope with enum symbol causing `undefined method `[]' for nil:NilClass`
# foo.rb
class Foo < ApplicationRecord
enum day: [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
validates :start_time, :end_time, overlap: {
scope: [:day, :another_column]
}
end
Here's what I got when validation fails:
undefined method `[]' for nil:NilClass
Extracted source (around line #184):
#182
#183 if is_enum_attribute?(record, attr_name)
*184 value = record.class.defined_enums[attr_name][value]
#185 end
#186
#187 value
...
I think you need to cast the attr_name
to string something like this attr_name.to_s
https://github.com/robinbortlik/validates_overlap/blob/4c2c837663379430e2605f9e66424d0a6e987f3f/lib/validates_overlap/overlap_validator.rb#L185