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

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

    To get the absolute URL which means that the from the root it can be displayed like this

    <%= link_to 'Edit', edit_user_url(user) %>
    

    The users_url helper generates a URL that includes the protocol and host name. The users_path helper generates only the path portion.

    users_url: http://localhost/users
    users_path: /users
    

提交回复
热议问题