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
if define reader method of ActiveModle::AttributeSet that named attributes, respond_to? raise NoMethodError #31832
Comments
ActiveRecord takes advantage of the internal def attributes
@attributes.to_hash
end You could actually do the same, but to be safe you should follow the public documentation and write: def attributes
{ 'hoge' => hoge }
end The short version: I don't think this is actually a bug. @rafaelfranca would it make sense to use |
I think this is a valid usage and this is how the system was designed to work. Once you add |
I suspect I have missed something here, but rails#31832 got me poking around in `ActiveModel::Attributes`, and I couldn't see where it was being used, except in a couple tests. If I am correct that this undocumented class is not being used anywhere in Rails, we should either remove it, or document it so people can use it. It does have some duplication with ActiveRecord::Attributes, so maybe we could clean that up as well. If I am NOT correct about any of this, I will be happy to learn why!
This starts to fix rails#31832. ActiveModel::Attributes includes ActiveModel::AttributeMethods, which requires an `#attributes` method that returns a hash with string keys.
Closed by #31926 |
Steps to reproduce
if define reader method of ActiveModle::AttributeSet that named attributes, respond_to? raise NoMethodError.
Expected behavior
It should return false.
use
key?
instead ofinclude?
Actual behavior
NoMethodError
System configuration
Rails-5.2.0.rc1
Ruby-2.4.3
The text was updated successfully, but these errors were encountered: