我定义了一个新的用户自定义字段:
User.find_each do |user|
user.custom_fields['foo'] = 0
user.save_custom_fields
end
这有效——现在每个用户都有 8 个自定义字段:
[18] pry(main)> User.find(1).custom_fields
=> {
"patreon_id" => "83297319",
"last_chat_channel_id" => 32,
"last_digest_special_post" => "275200",
"last_digest_favorite_post" => "279347",
"example_field" => "new value",
"ai_bot_query_count" => "0",
"ai_bot_query_date" => "2025-01-12",
"foo" => "0"
}
数据浏览器看到了新字段:
SELECT * from user_custom_fields
WHERE name LIKE '%foo%'
LIMIT 10
现在我想在 JavaScript 中使用 foo 字段。我在 /admin/customize/themes/3/common/head_tag/edit 添加了一些代码。但只有 8 个中的 2 个显示出来:
api.getCurrentUser().custom_fields
{
last_chat_channel_id: 32,
ai_bot_query_count: '0'
}
我错过了什么?
Moin
2
您是否已将用户字段添加到 public user custom fields 站点设置中?
2 个赞
谢谢,这招奏效了。
还有一个问题——这些自定义用户字段是不同的东西吗?
system
(system)
关闭
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.