0

I'm having some trouble with characters like spaces, plus signs, double quotes and accented latin characters in rails when adding them to urls as parameters. They are always converted to numbers preceded by %, and this is generating a lot of trouble for us, since portuguese uses a lot of those characters.

Everything works just fine when typing the character manually in the URL, but once rails makes it into a link, it'll replace it.

Is there a way to avoid that?

Here's an example. Instead of

url?q=transgênico

we get

url?q=transg%C3%AAnico

This completely breaks our search and communication with other websites through parameters - which works fine when typing the special characters manually.

I must admit I did not search about this, since english is not my first language and I have no clue what to search for... All my tries had no results, but I probably was using bad terms.

Using Rails 2.3.8.

Thank you in advance.

MarceloJ
  • 135
  • 1
  • 12

3 Answers3

3

I belive you have to encode those characters because they are not valid in a url: Uniform Resource Locators (URL) Spec and in stackoverflow

Community
  • 1
  • 1
wusher
  • 11,851
  • 22
  • 66
  • 94
0

I'd try setting the :escape => false flag in link_to and the like. If that doesn't help you'll have to monkey patch actionpack/lib/action_view/helpers/url_helper.rb probably.

Jakub Hampl
  • 36,560
  • 8
  • 70
  • 101
0

Maudite is right. You can convert this urls back to a 'nice' form before using it as search terms:

require 'cgi'
CGI.unescape 'url?q=transg%C3%AAnico'

produces:

"url?q=transgênico"
Marek Sapota
  • 18,366
  • 3
  • 31
  • 45