My Song model has a lyrics text attribute. Since new lines are \n-separated in my lyrics, I often find myself doing this in my views to make the lyrics HTML-friendly:
@song.lyrics.strip.gsub(/\n/, "\n<br />")
I'm repeating the gsub logic all over my application, and, worse still, I can't change the format in which I store my lyrics without touching everywhere I tried printing them as HTML.
I'd like to abstract this so that I can write this in my views:
@song.lyrics.to_html
So that the strip.gsub(/\n/, "\n<br />") logic is present in only one place in my application (in the to_html method).
What's the best way to do this?