Reputation: 9600
I'm implementing a blog with tags with some French characters. My question has to do with how to deal with spaces and unicode (utf-8) characters in the url.
let's say I have a tag called: ohlàlà! and I have the following code in my tag cloud:
<%= link_to h(tag.name.capitalize), { :controller => :blog, :action => :tag, :id => h(tag.name) }, :class => css_class %>
How do I deal with this issue?
Upvotes: 2
Views: 232
Reputation: 86442
See ToASCII and ToUnicode in this Wikipedia article. I hope the article has enough pointers to resolve your question.
Edit: Though it talks Python, Unicode and permalinks can give an idea about how to encode a solution to your question. To summarize:
Basically, the Unicode URL is encoded in UTF8 and each byte of the UTF8-encoded string is encoded using percent encoding. The browser apparently recognized this specific encoding scheme (which isn’t documented anywhere I could fine) and displays nice internationalized URLs for the user.
Sorry, I've no idea if Rails has a ready-made function to encode URLs this way.
Upvotes: 1