I'm trying to write a new macro for my ActiveRecord model (User). Macro will be defined in my own gem which called Kart.
Below is my implementation for my gem Kart and User
require "kart/version"
module Kart
extend ActiveSupport::Concern
included do
def goodbye
p "Gooooood"
end
end
end
ActiveSupport.on_load :active_record do
ActiveRecord::Base.send :include, Kart
end
class User < ApplicationRecord
goodbye # this is my macro, simply print "Goodbye"
end
For my understanding, when I run "rails c", "Gooooood" will be printed in the console but error message "method_missing': undefined local variable or methodgoodbye' for User" always shows up.
There are 2 main problems that I finally figure out:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With