Encoding::UndefinedConversionError
menu.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
This worked perfectly, I had to replace some extra characters but there are no more errors.
Encoding::UndefinedConversionError \xC2 from ASCII-8BIT to UTF-8 with redcarpet
in the end I solved this with adding force_encoding("UFT-8")
to the html
like this:
f.write html.force_encoding("UTF-8")
it fixed it.
`write': \xCF from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) while writing to file from url
Use force_encoding
:
open(uri) {|url_file| tempfile.write(url_file.read.force_encoding("UTF-8"))
Ruby on Rails - Encoding::UndefinedConversionError: \xC3 from ASCII-8BIT to UTF-8
For anybody that are coming here from google this is how I fixed my encoding error.
right before you declare of open your file add this code
.force_encoding("UTF-8")
so before you declare the file to a variable like this :
csv_file = params[:file].read.force_encoding("UTF-8")
Hope this will help some since I had this problem for a long time, but now it works yay!
Encoding::UndefinedConversionError: \xC2 from ASCII-8BIT to UTF-8
Your string is in some other encoding, most likely iso-8859-1, so you should run this to convert it:
"\xC2".encode("iso-8859-1").force_encoding("utf-8")
=> "Ã"
See this question for more information related to this issue.
Ruby on Rails Encoding::UndefinedConversionError ( \xF8 from ASCII-8BIT to UTF-8)
A simple solution was to give the File.write function the 'wb' rights
def self.convert_base64_to_file(directory: nil, file_name:, base64data:)
if directory
file_path = [directory, file_name].join('/')
else
file_path = file_name
end
file = File.open("file_name", 'w') {|f| f.write(Base64.decode64(base64data)) }
return file_path
end
I hope that'll help someone!
Related Topics
Error: Failed to Build Gem Native Extension When Installing Rails on MAC Mountian Lion Os
Ruby: File Encryption/Decryption with Private/Public Keys
Confusion About Passing Instance Variables to Redirect_To Method. as Seen in Rails Guides
Rails 3.1 Pipeline - Exclude JavaScript File
Sum the Value of Array in Hash
How to Use Bundler with Offline .Gem File
How to Alter the Timezone of a Datetime in Ruby
How to Fix Rubygems Recent Deprecation Warning
How to Simulate Java-Like Annotations in Ruby
Using Implicit 'Subject' with 'Expect' in Rspec-2.11
How to Uninstall Ruby from /Usr/Local
Including One Erb File into Another
Rails: Unpermitted Parameter in Rails 5