Discourse is not a simple rails application, I don’t believe the rails CLI will work for you.
Discourse is also fronted by an Ember SPA which is listening on port 4200.
You need to develop a plugin to achieve this.
Can I suggest you look at prior art in GitHub that does something similar, for example, I add a page here: GitHub - merefield/discourse-word-cloud: Generates a word cloud from the posts on your Discourse forum · GitHub