In my rails app I\'m working with RSS feeds from all around the world, and some feeds have links that are not in UTF-8. The original feed links are out of my control, and i
This will ensure you have the correct encoding and won't error out because it replaces any invalid or undefined character with a blank string.
This will ensure no matter what, that you have a valid UTF-8 string
str.encode(Encoding.find('UTF-8'), {invalid: :replace, undef: :replace, replace: ''})