Search code examples
ruby-on-railsurlencodingutf-8webrick

How can rails app accept non-alphanumeric character in url?


I am trying to construct search method by accepting some keywords as a GET request.

For exmaple, 'articles/search/computer' will likely search for articles that have keyword computer.

Now, if search term contains some other languages, such as Korean word, the rails app produces the following page.

Internal Server Error


"\x80" on CP949

WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18) at hanun.com:3000

and the server has log as follows

[2011-05-15 19:58:05] ERROR Encoding::InvalidByteSequenceError: "\x80" on CP949

I am in a window 7, with ruby 1.9.2p180, rails 3.0.5. I am using webrick as a development server. How can I resolve this problem so that the rails app will accept non-alphanumeric characters as url string??

This url does works: http://127.0.0.1/articles?search=한국

However, following url does not work: http://127.0.0.1/articles/search/한국


Solution

  • Ok, the problem was not from rails, but from OS. In windows, any non-alphabetic characters won't be accepted in url if it came in as a shorthand url in rails app. In linux, it works fine. This only happens to rails.

    Note that this problems only occurs in Webrick && windows 7 && rails environment.