J’ai défini un nouveau champ personnalisé pour l’utilisateur :
User.find_each do |user|
user.custom_fields['foo'] = 0
user.save_custom_fields
end
Cela fonctionne - maintenant chaque utilisateur a 8 champs personnalisés :
[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 voit le nouveau champ :
SELECT * from user_custom_fields
WHERE name LIKE '%foo%'
LIMIT 10
Maintenant, je veux utiliser le champ foo en javascript. J’ai ajouté du code à /admin/customize/themes/3/common/head_tag/edit. Mais seulement 2 des 8 apparaissent :
api.getCurrentUser().custom_fields
{
last_chat_channel_id: 32,
ai_bot_query_count: '0'
}
Qu’est-ce qui me manque ?
Moin
Janvier 12, 2025, 2:51
2
Avez-vous ajouté vos champs utilisateur au paramètre du site champs personnalisés utilisateur publics ?
This guide explains how to expose user custom field data through the API without displaying it on a user card.
Required user level: Administrator
This guide will walk you through the process of making User Custom Field data accessible via the API without displaying it on a user card. This can be useful when you need to programmatically access custom user data while keeping it hidden from general view.
Creating a User Custom Field
First, create your User Cu…
2 « J'aime »
Merci, ça a fonctionné.
Une autre question : ces champs utilisateur personnalisés sont-ils une chose différente ? :
This guide explains how to create and configure custom user fields in Discourse, including how to add them to the signup form, user profiles, and user directory.
Required user level: Administrator
Custom user fields allow you to collect additional information from your users beyond the standard profile fields. These fields can be displayed on user cards, user summary pages, and even retrieved using the Data Explorer plugin. This guide will walk you through th…
system
(system)
A fermé ce sujet ()
Février 11, 2025, 3:05
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.