Created
February 10, 2013 14:46
-
-
Save puffy/4749787 to your computer and use it in GitHub Desktop.
The pretty way to break away of invalid utf-8 byte sequence error in ruby 1.9
# code got from http://robots.thoughtbot.com/post/42664369166/fight-back-utf-8-invalid-byte-sequences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def replace_name(body, name) | |
body | |
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') | |
.gsub(/joel/, name) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment