# total_points is a sum table with column "total_earned_points".
module MyModel::UserExtension
def self.prepended(base)
base.has_many :user_points, class_name: 'MyModel::UserPoint'
base.has_one :total_point, class_name: 'MyModel::TotalPoint'
end
end
reloadable_patch do |plugin|
User.class_eval { prepend MyModel::UserExtension }
end
add_to_class(:user, :total_earned_points) do
# self.user_points.sum(:reward_points)
self.total_point[:total_earned_points]
end
I am very new to rails. Could you please tell me what is wrong with it?
Thanks so much!
Something that you expect to be an array is nil. Mabye args is nil and needs to be a []?
You can also take a look at GitHub - discourse/all-the-plugins to try to find examples of what you’re trying to do (I can’t quite tell what you’re trying to do).
Check out discourse-calendar. It adds an Event class, which seems pretty analogous to what you’re trying to do.
There are a bunch of plugins taht have a similar reloadable_patch block, though.