# כיצד אוכל להוסיף מאפיין למודל המשתמש?

**URL:** <https://meta.discourse.org/t/how-can-i-add-an-attribute-to-user-model/237348>\
**Category:** Development\
**Created:** [27 באוגוסט,‏ 2022,‏ 5:27pm UTC](https://meta.discourse.org/t/how-can-i-add-an-attribute-to-user-model/237348 "2022-08-27T17:27:48Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Alienazk](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alienazk/32/261130_2.png) [@Alienazk](https://meta.discourse.org/u/Alienazk)\
**Post date:** [27 באוגוסט,‏ 2022,‏ 5:27pm UTC](https://meta.discourse.org/t/how-can-i-add-an-attribute-to-user-model/237348/1 "2022-08-27T17:27:48Z")

</div>

I am trying to modify a plugin.  
The following code failed and threw an error like:

 ![屏幕快照 2022-08-28 02.22.02](https://global.discourse-cdn.com/meta/original/4X/a/e/9/ae95b46cccfe504e00811fcae6fcbbdaf65c34fe.png)

```plaintext
# 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

```

```plaintext
 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!

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-add-an-attribute-to-user-model/237348)._
