Definisco un nuovo campo personalizzato per l’utente:
User.find_each do |user|
user.custom_fields['foo'] = 0
user.save_custom_fields
end
Questo funziona: ora ogni utente ha 8 campi personalizzati:
[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 vede il nuovo campo:
SELECT * from user_custom_fields
WHERE name LIKE '%foo%'
LIMIT 10
Ora voglio usare il campo foo in javascript. Aggiungo del codice in /admin/customize/themes/3/common/head_tag/edit. Ma solo 2 degli 8 vengono visualizzati:
api.getCurrentUser().custom_fields
{
last_chat_channel_id: 32,
ai_bot_query_count: '0'
}
Cosa mi sto perdendo?
Moin
12 Gennaio 2025, 2:51pm
2
Hai aggiunto i tuoi campi utente all’impostazione del sito campi personalizzati utente pubblici?
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 Mi Piace
Grazie, ha funzionato.
Un’altra domanda: questi campi utente personalizzati sono una cosa diversa?
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)
Chiuso
11 Febbraio 2025, 3:05pm
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.