How to override Rails read method cache access attributes?
Many gems override Rails attribute attributes using the following code:
define_method "#{dynamic_name}" do
value = read_attribute(dynamic_name)
# Do stuff
end
Or that:
belongs_to :user
def user
# Do stuff
end
Rails 4.2 introduced a cache for atttribute methods ( AttributeMethodCache
, ReaderMethodCache
, https://github.com/rails/rails/pull/15429 )
This results in incorrect values ββwhen accessing overriden attributes using the above methods. It looks like the return values ββfrom the original read methods are cached and returned even after the method is overridden.
What is the recommended procedure for overriding attribute assemblers in Rails 4.2?
+3
source to share
No one has answered this question yet
Check out similar questions: