Almost 1 hour of digging before i gave up and built this…
(Does not support https yet)
# /abs -> http://myx.com/abs
def path_to_url(path)
"http://#{request.host_with_port_without_standard_port_handling}/#{path.sub(%r[^/],'')}"
end
Building web applications and fighting the daily madness
Almost 1 hour of digging before i gave up and built this…
(Does not support https yet)
# /abs -> http://myx.com/abs
def path_to_url(path)
"http://#{request.host_with_port_without_standard_port_handling}/#{path.sub(%r[^/],'')}"
end
3 comments
Comments feed for this article
2008-11-24 at 18:48:14
Luis Lavena
Hmn,
url_for for full path didn’t do the job?
http://apidock.com/rails/ActionController/Base/url_for
2008-11-24 at 19:01:51
pragmatig
nope, not enough when you got /xy/something (for example an image) and want to generate the url for it
url_for(‘/path’) only generates ‘/path’ kind of disappointing
2012-03-12 at 19:07:09
Will Sulzer
Here’s mine. This works in Rails 3.1. I needed to use this method because if was needed a full path to assets, and Rails would only give me the relative paths, i.e. image_path(‘foo’), video_path(‘bar’). It’s too bad that they don’t support image_url, etc..
def path_to_url(path)
“#{request.protocol}#{request.host_with_port}#{path}”
end