添加activesupport-json_encoder gem到Gemfile中修复此问题。
我使用回形针进行图像存储,当我尝试上传和保存图像时,图像被保存,但我在重定向到其他页面时获得Encoding::UndefinedConversionError
。
我试图删除回形针代码并使用正常的文件上传机制做相同的操作,但结果是相同的。
Parameters: {"utf8"=>"✓", "authenticity_token"=>"janP4YndP+9xORuxP5BkEuRFpVZi7GvLcs3u+6RsSfs=", "user"=>{"profile_picture"=>#ActionDispatch::Http::UploadedFile:0x3622916a @original_filename="36.jpg", @headers="Content-Disposition: form-data; name="user[profile_picture]"; filename="36.jpg"rnContent-Type: image/jpegrn", @tempfile=#<Tempfile:/home/ROOT/RackMultipart.13883.61589>, @content_type="image/jpeg">}}
Command :: file -b --mime
'/home/ROOT/36130617-13883-1gqm197-61590130617-13883-1uub191-61593'
(1.0ms) UPDATE `users` SET `avatar_file_name` = '36.jpg', `avatar_file_size` = 107409, `avatar_updated_at` = '2013-06-17 13:44:04', `updated_at` = '2013-06-17 13:44:04' WHERE `users`.`id` = 10
[paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/original/123.jpg
[paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/medium/123.jpg
[paperclip] deleting /home/ROOT/public/system/users/avatars/000/000/010/thumb/123.jpg
Redirected to url
Encoding::UndefinedConversionError - "xFF" from ASCII-8BIT to UTF-8:
org/jruby/RubyString.java:7580:in `encode'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:123:in `escape'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:69:in `escape'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:171:in `encode_json'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:214:in `encode_json'
org/jruby/RubyArray.java:2361:in `map'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:214:in `encode_json'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:48:in `encode'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:77:in `check_for_circular_references'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:46:in `encode'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:246:in `encode_json'
org/jruby/RubyHash.java:1257:in `each'
org/jruby/RubyEnumerable.java:718:in `map'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:246:in `encode_json'
(gem) activesupport-3.2.13/lib/active_support/json/encoding.rb:48:in `
我检查了回形针宝石,它使用binmode打开文件
删除了对用于自定义编码的encode_json钩子的支持对象转换为JSON。该特性已被提取到activesupport-json_encoder宝石。