Ich definiere ein neues benutzerdefiniertes Feld für Benutzer:
User.find_each do |user|
user.custom_fields['foo'] = 0
user.save_custom_fields
end
Das funktioniert – jetzt hat jeder Benutzer 8 benutzerdefinierte Felder:
[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"
}
Der Data Explorer sieht das neue Feld:
SELECT * from user_custom_fields
WHERE name LIKE '%foo%'
LIMIT 10
Jetzt möchte ich das Feld foo in JavaScript verwenden. Ich füge etwas Code unter /admin/customize/themes/3/common/head_tag/edit hinzu. Aber nur 2 der 8 werden angezeigt:
api.getCurrentUser().custom_fields
{
last_chat_channel_id: 32,
ai_bot_query_count: '0'
}
Was übersehe ich?
Moin
12. Januar 2025 um 14:51
2
Haben Sie Ihre Benutzerfelder zur Website-Einstellung public user custom fields hinzugefügt?
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 „Gefällt mir“
Danke, das hat funktioniert.
Noch eine Frage: Sind diese benutzerdefinierten Benutzerfelder etwas anderes?
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)
Geschlossen,
11. Februar 2025 um 15:05
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.