The discussion revolves around displaying a numeric badge from an external source in a user’s profile. Morokiel wants to fetch a user-specific value (e.g., points) via JavaScript and show it in a badge. pfaffman suggests using a user custom field via the API or a plugin to store and retrieve the value, advising against direct database manipulation. Morokiel confirms understanding and plans to use a custom field. pfaffman clarifies that a user_custom_field should be used instead of direct database changes. Morokiel asks how to display the custom field value in the badge UI, and pfaffman explains that a plugin can add the field to the serializer and render it in the badge, referencing existing plugin code for guidance.
Hi, I have a customer who wants to display a custom badge in users profile.
I have to get the badge value in javascript from an external source, so I will call a function with the username as a parameter and this function will return a value for the badge.
Got it, I will add a new field in the database then I could create a script to populate that field. Then I will create a badge selecting this new field
You almost certainly don’t want to do that. You can use a user_custom_field (or maybe that’s what you meant, since it’s sort-of the same thing) or the similarly-named-thing in the user customization on the UX.
Understood. One last question, I searched sql queries for granting badges, and I couldn’t find an example who display a user_custom_field in the UI. They just look into the user_custom_field to grant the badge
For example in the screenshot I attached before, The number 105.230 should be stored in the user_custom_field and I need to display it in the badge
I’d have to look at the code to give you real answers.
What you want to do is have your plugin add that custom field to the serializer. You can search some existing plugins for add_to_serializer in plugin.rb for some examples. Then you can wrangle that into the badge on the front end.