How do I get the current absolute URL in Ruby on Rails?

后端 未结 30 2500
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 13:47

How can I get the current absolute URL in my Ruby on Rails view?

The request.request_uri only returns the relative URL

30条回答
  •  一个人的身影
    2020-11-22 14:10

    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
    

提交回复
热议问题