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

后端 未结 30 2691
佛祖请我去吃肉
佛祖请我去吃肉 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:17

    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}"
    

提交回复
热议问题