Skip to content

Instantly share code, notes, and snippets.

@Austio
Last active December 2, 2015 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Austio/85c4315f5baef2ee73d0 to your computer and use it in GitHub Desktop.
Save Austio/85c4315f5baef2ee73d0 to your computer and use it in GitHub Desktop.
Error occuring when using active record enum inside of a nested active record class.
From: /../gems/activerecord-4.1.11/lib/active_record/attribute_methods.rb @ line 129 ActiveRecord::AttributeMethods::ClassMethods#method_defined_within?:
128: def method_defined_within?(name, klass, superklass = klass.superclass) # :nodoc:
=> 129: if klass.method_defined?(name) || klass.private_method_defined?(name)
130: if superklass.method_defined?(name) || superklass.private_method_defined?(name)
131: klass.instance_method(name).owner != superklass.instance_method(name).owner
132: else
133: true
134: end
135: else
136: false
137: end
138: end
[13] pry(::Network::Contact)> klass.method_defined?(name)
=> true
[14] pry(::Network::Contact)> name
=> "informed_consent_request_state="
[15] pry(::Network::Contact)> klass
=> #<Module:0x0000000c34a7b8>
[16] pry(::Network::Contact)> klass.methods.grep(/informed_consent_request/)
=> []
@Austio
Copy link
Author

Austio commented Dec 2, 2015

Error raising for enum because it detects a method being defined (informed_consent_request_state=) on klass that does not exist.

@apneadiving
Copy link

I see, I guess/recall its due to require. What if you use load instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment