APIではカスタムユーザーフィールドが利用できません

新しいユーザーカスタムフィールドを定義します。

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"
}

Data Explorer で新しいフィールドが表示されます。

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'
}

何が足りないのでしょうか?

public user custom fields のサイト設定にユーザーフィールドを追加しましたか?

「いいね!」 2

ありがとうございます。うまくいきました。

もう一つ質問ですが、これらはカスタムユーザーフィールドとは別のものですか?

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