公告
财富商城
积分规则
提问
发文
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
you can use any one for rails 3.2:
request.original_url or request.env["HTTP_REFERER"] or request.env['REQUEST_URI']
I think it will work every where
"#{request.protocol}#{request.host}:#{request.port}#{request.fullpath}"
It looks like request_uri is deprecated in Ruby on Rails 3.
request_uri
Using #request_uri is deprecated. Use fullpath instead.
I needed the application URL but with the subdirectory. I used:
root_url(:only_path => false)
I think request.domain would work, but what if you're in a sub directory like blah.blah.com? Something like this could work:
<%= request.env["HTTP_HOST"] + page = "/" + request.path_parameters['controller'] + "/" + request.path_parameters['action'] %>
Change the parameters based on your path structure.
Hope that helps!
You can use the ruby method:
:root_url
which will get the full path with base url:
localhost:3000/bla
In Ruby on Rails 3.1.0.rc4:
request.fullpath
最多设置5个标签!
you can use any one for rails 3.2:
I think it will work every where
It looks like
request_uri
is deprecated in Ruby on Rails 3.I needed the application URL but with the subdirectory. I used:
I think request.domain would work, but what if you're in a sub directory like blah.blah.com? Something like this could work:
Change the parameters based on your path structure.
Hope that helps!
You can use the ruby method:
which will get the full path with base url:
In Ruby on Rails 3.1.0.rc4: