Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scope with enum symbol causing undefined method []' for nil:NilClass` #54

Open
denmarkmeralpis opened this issue Dec 18, 2019 · 0 comments

Comments

@denmarkmeralpis
Copy link

# 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

value = record.class.defined_enums[attr_name][value]

denmarkmeralpis added a commit to denmarkmeralpis/validates_overlap that referenced this issue Dec 18, 2019
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

No branches or pull requests

1 participant