将带有punycode的转义网址转换为utf,重构

时间:2011-04-25 22:12:52

标签: ruby-on-rails ruby idn punycode

我想将所有网址存储在可读的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

重构或更多通用宝石的任何提示?

0 个答案:

没有答案