Answer the question
In order to leave comments, you need to log in
How to properly encode url with russian characters in Rails 4?
Hello!
I write on RoR 4 recently. I have also been doing programming recently, in connection with this there is not enough knowledge to solve this problem, namely:
when you click on this link:
http://maps.yandex.ru/?text=sberbank&sll=50.186334...
this appears error:
bad URI(is not URI?): http://maps.yandex.ru/?text=sberbank&sll=50.186334...
If I change "sberbank" to "sberbank" everything works fine.
def yandex_map(number)
require 'open-uri'
require 'rubygems'
require 'nokogiri' #-парсинг HTML
require 'json' #-парсинг json
require 'uri' #-открытие по URL
@html = open("http://maps.yandex.ru/?text=сбербанк&sll=50.18633499999997%2C53.216120999997734&sspn=0.377655%2C0.123853&z=12&results=20&ll=50.186333%2C53.216119&spn=0.377655%2C0.123853&l=map")
@nokogiri = Nokogiri::HTML(@html)
@may = @nokogiri.css('#vpage').inner_text
@j_parse = JSON.parse(@may)
json_companys = Array.new(number)
json_telefons = Array.new(number)
number.times do |i|
json_companys[i] = @j_parse['vpage']['data']['businesses']['GeoObjectCollection']['features'][i]['properties']['name']
end
return json_companys
end
Answer the question
In order to leave comments, you need to log in
require 'uri'
=> true
irb(main):002:0> URI.escape("http://maps.yandex.ru/?text=сбербанк&sll=50.18633499999997%2C53.216120999997734&sspn=0.377655%2C0.123853&z=12&results=20&ll=50.186333%2C53.216119&spn=0.377655%2C0.123853&l=map")
=> "http://maps.yandex.ru/?text=%D1%81%D0%B1%D0%B5%D1%80%D0%B1%D0%B0%D0%BD%D0%BA&sll=50.18633499999997%252C53.216120999997734&sspn=0.377655%252C0.123853&z=12&results=20&ll=50.186333%252C53.216119&spn=0.377655%252C0.123853&l=map"
URI.escape
works fine for me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question