I have a model called Feature with a variable called body_string that contains the HTML markup that I would like to display, not escape.
Every time I refer to body_string in my views, I need to use <%=raw or .html_safe . It seems redundant and not very dry.
Is there a way that I can set the body_string variable somehow and all for myself as html_safe ?
I assume that this will happen in the app/models/feature.rb , but I cannot figure out what exactly will be the correct syntax. I thought about this:
def body_string return self.body_string.html_safe end
But he doesn't like Rails; it throws a stack level too deep exception.
Naturally, I could define a variable / method with a different name:
def safe_body_string return self.body_string.html_safe end
And then just change all the links in the views from body_string to safe_body_string . But for some reason it seems almost NOT DRY, just using raw or .html_safe in the first place.
Any ideas on how best to deal with this? I feel that there must be something really elegant that I just donβt see.
source share