Does ECR support unicode/emoji string values?

I have a blog project using Kemal where some of my post titles and post page content could have emoji characters.

I can see the emoji if I render static html which has them, and I can see the emoji in the Postgres data. I even have a Spec which tests the Postgres post title value with the expected emoji string. It passes.

However, if I have a ECR template which tries to render the variable which has emoji, the emoji isn’t rendered.

<ul>
<%- posts.each do |post| -%>
<li><a href="<%= post.url %>"><%= post.title %></a></li>
<%- end -%>
</ul>

What gets displayed is the literal unicode characters, not the emoji.

Is there something I need to do to enable this? Maybe an .encode or .html_safe or something similar?

Two questions:

  • if you have emoji directly in a string (not coming from the DB), does it still break?
  • Do you have <meta charset="UTF-8"> in your HTML head?
1 Like

What does that mean?

I forget that meta tag every time. Same with the viewport meta tag for mobile.

Yes, the missing <meta charset="UTF-8"> was the issue. Ironically, I had that on all of my other views, but not this one I was testing. :man_facepalming:t2:

Thanks!