I would like to let users use variable name inside text box with Trix.
Given a trix text-box that let the user write messages to other user, I would like to be able to do something like this: "Hello %user_name%"
When sending the message the user_name would be changed to whatever is the user_name.
I would except this to be a fairly standard feature but couldn't find mention of it in the documentation or SO.
I have tried doing a simple .gsub
on the model.content.body but this is returning and ActionText::RichText
who doesn't know what gsub is.
An easy way to mock variables within text contents is to use search and replace, just replace the strings within the action that receives posted contents:
Note that gsub is only available for string type.