Check if the `request` variable isn't nil when calling render_to_string

closes #14125
Merge pull request #14129 from joankaradimov/fix-render-to-string

Fix `render_to_string` when called via manually instantiated controllers