Help us understand the problem. What is going on with this article?

Rubyで日本語のURI(URL)をパーズするなら Addressable::URI を使おう

More than 5 years have passed since last update.

Rubyの標準URIクラスでは日本語を含むURIをparseすることはできません(どのRFCを対応しているかの関係らしいです)。
なので解決方法としては Addressable::URI というgemがあるのでそれを使用することで日本語URIに対応することができます。

ライブラリURL
https://github.com/sporkmonger/addressable

# Gemfile
gem 'addressable', require: 'addressable/uri'

# bundle 実行...

# rails console にて確認

URI.parse('http://ja.wikipedia.org/wiki/日本語')
#=> URI::InvalidURIError: bad URI(is not URI?): http://ja.wikipedia.org/wiki/日本語

Addressable::URI.parse('http://ja.wikipedia.org/wiki/日本語')
#=> #<Addressable::URI:0x3fc05653a740 URI:http://ja.wikipedia.org/wiki/日本語>

■ 参考
本家
https://github.com/sporkmonger/addressable
情報
http://d.hatena.ne.jp/kitamomonga/20100316/ruby_gem_addressable_howto
http://memo.yomukaku.net/entries/220

yoshioota
フリーでプログラマしてます
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした