# 升级到新版本时出现“参数数量错误”

**URL:** <https://meta.discourse.org/t/wrong-number-of-arguments-on-upgrade-to-new-version/262083>\
**Category:** Development\
**Created:** [2023年四月18日 13:32 UTC](https://meta.discourse.org/t/wrong-number-of-arguments-on-upgrade-to-new-version/262083 "2023-04-18T13:32:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paresy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paresy/32/96471_2.png) [@paresy](https://meta.discourse.org/u/paresy)\
**Post date:** [2023年四月18日 13:32 UTC](https://meta.discourse.org/t/wrong-number-of-arguments-on-upgrade-to-new-version/262083/1 "2023-04-18T13:32:58Z")

</div>

我已升级到 3.1.0.beta4，但现在我的一个插件不再工作了，我很难弄清楚如何升级这部分代码：

```plaintext
after_initialize do

  User.register_custom_field_type('myfield', :json)

  # 我们需要使其可编辑以允许 API 访问
  register_editable_user_custom_field :myfield
  register_editable_user_custom_field myfield: {} **---- 错误在此**

  # 这会将字段添加到 post json 中
  add_to_serializer(:post, :user_myfield, false) {
    # 管理员是 Admin + Moderator
    object.user.custom_fields['myfield'] if object.user && scope.is_staff?
  }

end

```

这是升级期间的错误：

```plaintext
I, [2023-04-18T13:14:53.725429 #1] INFO -- : > cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate'
rake aborted!
ArgumentError: wrong number of arguments (given 0, expected 1)
/var/www/discourse/lib/plugin/instance.rb:185:in `register_editable_user_custom_field'
/var/www/discourse/plugins/discourse-test-information/plugin.rb:18:in `block in activate!'
/var/www/discourse/lib/plugin/instance.rb:507:in `block in notify_after_initialize'
/var/www/discourse/lib/plugin/instance.rb:505:in `each'
/var/www/discourse/lib/plugin/instance.rb:505:in `notify_after_initialize'
/var/www/discourse/config/application.rb:228:in `each'
/var/www/discourse/config/application.rb:228:in `block (2 levels) in <class:Application>'
/var/www/discourse/lib/plugin.rb:6:in `initialization_guard'
/var/www/discourse/config/application.rb:228:in `block in <class:Application>'

```

有人能给我一些关于发生了什么变化的提示，以及我需要如何调整我的代码吗？

谢谢，此致，  
Michael

---

<div class="post-metadata">

**Author:** ![paresy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paresy/32/96471_2.png) [@paresy](https://meta.discourse.org/u/paresy)\
**Post date:** [2023年四月18日 13:53 UTC](https://meta.discourse.org/t/wrong-number-of-arguments-on-upgrade-to-new-version/262083/2 "2023-04-18T13:53:19Z")

</div>

我找到了答案：[Add a custom per-user setting in a plugin](https://meta.discourse.org/t/add-a-custom-per-user-setting-in-a-plugin/94048)

第一个帖子已正确更新，我需要将我的行更新为：

> register\_editable\_user\_custom\_field [:myfield, myfield : {}]

paresy

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)\
**Post date:** [2023年五月18日 13:53 UTC](https://meta.discourse.org/t/wrong-number-of-arguments-on-upgrade-to-new-version/262083/3 "2023-05-18T13:53:32Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
