I have a User model, which includes module Staff:
class User < ActiveRecord::Base
include Staff
...
end
I want to add an after_update callback to all the models that include this module:
module Staff
def self.included(model)
model.class_eval do
after_update :callback
end
end
private
def callback
...
end
end
I get a NoMethodError:
undefined method `after_update' for Object:Class
What am I doing wrong?
Solved! The problem was that I had another class including my module Staff, which was not an ActiveRecord model.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.