Hello Discourse community!
I’m new to Discourse and trying to use my few ruby knowledge. Thanks for your help !
Here is my project :
I created custom fields to get to know a new user better and now I want to update the custom field for old users.
I want to display my question at login if the field is empty.
If I understand Discourse correctly, I need to code a plugin.
Do you have a tip or an example in mind for this first challenge?
Thanks in advance !
In rails console, i use
UserCustomField.where.not(value: [nil])
to find users who have already replied but for the rest I dry…
How to get users who haven’t answered the question?
Guess I’ll need to figure this out later.
Two suggestions:
-
Consider asking how to solve your problem (getting users to fill the in the field). The user wizard plugin might be a solution?
-
Move this to dev and ask there. I think that it might be possible with a theme component if the values are in serializer.
For either, change he subject to something like “how can I force users to fill in a custom field when it’s empty”
I don’t have a very good answer, though.
To that specific question, assuming that an unanswered question will be NULL in the database, you can just replace where.not(value: [nil])
with where(value: nil)
.
You can also use where(value: [nil, ""])
, which is equivalent to WHERE (something.value IS NULL OR something.value = "")
in SQL, to search for an empty string or NULL. I’m not sure which it’s likely to be or if it’s likely to change (from NULL to “”) if a user submits an empty field.
Thanks @pfaffman. I will follow your advice.
Thanks @Simon_Manning for this precision. That will help me a lot !
This plugin is great. Thanks @pfaffman
Thanks again guys. Custom wizard plugin works very well