开发者

converting escaped urls with punycode to utf, refactoring

开发者 https://www.devze.com 2023-02-28 11:28 出处:网络
I want to store all my url in readble utf8 class User < ActiveRecord::Base require \'addressable/uri\'

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 refactor开发者_JAVA百科ing or for more universal gems?

0

精彩评论

暂无评论...
验证码 换一张
取 消