Rails View Encoding Issues

后端 未结 2 2048
粉色の甜心
粉色の甜心 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:38

    That error message usually occurs when you try to concatenate strings with different character encodings.

    Is your database set to use UTF-8 as well?

    If not, you could have a problem when you try to insert the non-UTF8 values into your UTF-8 template.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题