ruby-on-rails – 为什么我在UTF-8中获得无效的字节序列

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 为什么我在UTF-8中获得无效的字节序列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么我会收到此错误
invalid byte sequence in UTF-8

用于加载图像:

= image_tag 'features_home/show1.png'

编辑

我注意到这个问题发生在我进行捆绑更新之后,任何图像都会出现错误..我会尝试在此处添加详细信息:

堆栈跟踪:

Rendered home/home.html.haml within layouts/application (229.9ms)
Completed 500 Internal Server Error in 1047ms
invalid byte sequence in UTF-8 excluded from capture: DSN not set

ActionView::Template::Error (invalid byte sequence in UTF-8):
    81:           / Carousel items
    82:           .carousel-inner
    83:             .active.item
    84:               = image_tag 'features_home/show1.png'
    85:               -#.carousel-caption
    86:               -#  %h4
    87:               -#  %p
  app/views/home/home.html.haml:84:in `block in _app_views_home_home_html_haml__623651309533727079_70331260863620'
  app/views/home/home.html.haml:33:in `_app_views_home_home_html_haml__623651309533727079_70331260863620'
  lib/rack/SEOredirect.rb:20:in `call'


  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (115.6ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (23.1ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.7ms)
  Rendered /Users/Apple/.rvm/gems/ruby-2.2.2@myapp/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (237.9ms)

捆绑更新前后的Gemfile.lock:https://gist.github.com/hopewise/35c2a98b13ac646b65770feb2f3c7ec8

完整追踪:
https://gist.github.com/hopewise/551169518a5938647dc767d3de393cd4

我不知道哪个宝石造成了这个问题..

解决方法

这似乎是Haml用于解析image_tag指令路径的less-rails gem中的错误.

调用image_tag时,less-rails最终会尝试扫描文件所依赖的资产,但可能会无意中使用非文本文件.这会导致您遇到的错误.

项目中(有点过时的)分支上的fix exists,用于正确验证路径.我们可以参加测试:

gem 'less-rails',github: 'Metaskills/less-rails',branch: 'depends_only_on_less_files'

有关更多详细信息,请参阅this ticket.正如那里所建议的那样,您可能需要验证代码是否使用了适合图像的路径.

猜你在找的Ruby相关文章