公告
财富商城
积分规则
提问
发文
2018-12-31 17:11发布
冷夜・残月
How can I get the current absolute URL in my Ruby on Rails view?
The request.request_uri only returns the relative URL.
request.request_uri
If by relative, you mean just without the domain, then look into request.domain.
request.domain
request.env["REQUEST_URI"]
works in rails 2.3.4 tested and do not know about other versions.
if you want to be specific, meaning, you know the path you need:
link_to current_path(@resource, :only_path => false), current_path(@resource)
For Rails 3.2 or Rails 4 Simply get in this way "request.original_url" Reference: Original URL Method
For Rails 3 As request.url is deprecated.We can get absolute path by concatenating
"#{request.protocol}#{request.host_with_port}#{request.fullpath}"
For Rails 2
request.url
You can use:
request.full_path
or
Hopefully it will resolve your problem.
Cheers
DEPRECATION WARNING: Using #request_uri is deprecated. Use fullpath instead.
最多设置5个标签!
If by relative, you mean just without the domain, then look into
request.domain
.works in rails 2.3.4 tested and do not know about other versions.
if you want to be specific, meaning, you know the path you need:
For Rails 3.2 or Rails 4 Simply get in this way "request.original_url" Reference: Original URL Method
For Rails 3 As request.url is deprecated.We can get absolute path by concatenating
For Rails 2
You can use:
or
Hopefully it will resolve your problem.
Cheers
DEPRECATION WARNING: Using #request_uri is deprecated. Use fullpath instead.