Hi everyone,
I have set up a ranking system with custom titles, but as you know, Discourse doesn’t have a built-in way to assign a default title to all new users. So, I created a workaround where:
- New members are in Group 1
- Active members are in Group 2
- And so on…
The method I used is as follows:
cd /var/discourse
./launcher enter app
rails c
User.where(trust_level: 0).update_all(title: "عضو جديد")
User.where(trust_level: 1).update_all(title: "عضو جديد")
User.where(trust_level: 2).update_all(title: "عضو مشارك")
User.where(trust_level: 3).update_all(title: "عضو مبدع")
The Problem
I have to run these commands manually every time a new user joins. If I run the script today and a new member posts tomorrow, they won’t get the title automatically, so I have to log in to the server and re-run the commands.
I tried automating it with a Ruby script and calling it via crontab, but I get an error.
I asked ChatGPT, and it told me:
“The User model is not loaded when you run the script directly with Ruby outside of the Discourse environment.”
The issue is that I don’t have the proper config/environment setup inside the Discourse files.
I added It, but it didn’t work.
My Question
Is there a way to automate this without using crontab? Or how can I properly execute a script that updates user titles without manually entering the Rails console each time?
Thanks in advance!