2

I want to store all my url in readble utf8

class User < ActiveRecord::Base
  require 'addressable/uri'
  require 'idn'
  include IDN
  def service_url=(url)
    url = Addressable::URI.parse Addressable::URI.unescape(url)
    url.host = Idna.toUnicode url.host
    super url.to_s
  end
end

any hints for refactoring or for more universal gems?

Oleg German
  • 135
  • 1
  • 6
  • I'm going to ask why you want to store them as UTF-8. Yes, they will give you a visible representation of the multibyte characters, but, you can run into problems with backend databases not liking the characters being injected into the table. It's something to consider. +1 for using Addressable::URI for this. – the Tin Man Apr 25 '11 at 23:34
  • See this post (hope it helps): http://stackoverflow.com/a/9648504/6594668 – prograils Dec 13 '16 at 12:27

0 Answers0