Hello everyone.
I am having the encoding issue on a simple file upload action:
Encoding::UndefinedConversionError in MainController#upload
"\xC4" from ASCII-8BIT to UTF-8
The action looks like this:
def upload
@uploaded_io = params[:upload]
File.open(Rails.root.join('public', 'images',
@uploaded_io.original_filename), 'w') do |file|
file.write(@uploaded_io.read)
end
end
I changed File.open to 'wb' (binary) and it woked fine. I also tried
switching the ruby version to 1.8.7 while leaving the File.open method
as 'w' (write) which also worked as expected, without any errors.
Should I use 'wb' everytime I want to use files from the filesystem,
or is it the ruby-1.9.2-p0 that comes with RVM cases the issue?
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment