Rails View Encoding Issues

后端 未结 2 2071
粉色の甜心
粉色の甜心 2021-01-06 01:02

I\'m using Ruby 2.0 and Rails 3.2.14. My view is littered several UTF-8 characters, mainly currency symbols like บาท and د.إ etc. I noticed some

(ActionView         


        
2条回答
  •  甜味超标
    2021-01-06 01:47

    The culprit that was leaking non UTF-8 characters in my template was an innocuous meta tag for Facebook Open Graph

    %meta{property: "og:url", content: request.url}
    

    And when the request is non-standard, this causes the encoding issue. Changing it to

    %meta{property: "og:url", content: request.url.force_encoding('UTF-8')}
    

    made the trick.

提交回复
热议问题