0Day Forums
How do I get the current absolute URL in Ruby on Rails? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Ruby (https://0day.red/Forum-Ruby)
+--- Thread: How do I get the current absolute URL in Ruby on Rails? (/Thread-How-do-I-get-the-current-absolute-URL-in-Ruby-on-Rails)

Pages: 1 2 3 4


How do I get the current absolute URL in Ruby on Rails? - dom837 - 07-18-2023

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

The `request.request_uri` only returns the **relative** URL.


RE: How do I get the current absolute URL in Ruby on Rails? - colistins93752 - 07-18-2023

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!


RE: How do I get the current absolute URL in Ruby on Rails? - archerayqli - 07-18-2023

(url_for(:only_path => false) == "/" )? root_url : url_for(:only_path => false)


RE: How do I get the current absolute URL in Ruby on Rails? - aniaijtcsakowb - 07-18-2023

If by relative, you mean just without the domain, then look into `request.domain`.





RE: How do I get the current absolute URL in Ruby on Rails? - karlenkissbsep - 07-18-2023

I think that the Ruby on Rails 3.0 method is now `request.fullpath`.




RE: How do I get the current absolute URL in Ruby on Rails? - disembowel855884 - 07-18-2023

It looks like `request_uri` is deprecated in Ruby on Rails 3.

Using #request_uri is deprecated. Use fullpath instead.



RE: How do I get the current absolute URL in Ruby on Rails? - actiniferous621020 - 07-18-2023

In Ruby on Rails 3.1.0.rc4:

request.fullpath



RE: How do I get the current absolute URL in Ruby on Rails? - ranicexxcomigmzz - 07-18-2023

For Ruby on Rails 3:

request.url
request.host_with_port

I fired up a debugger session and queried the request object:

request.public_methods



RE: How do I get the current absolute URL in Ruby on Rails? - niela707 - 07-18-2023

I needed the application [URL][1] but with the subdirectory. I used:

root_url(:only_path => false)

[1]:

[To see links please register here]




RE: How do I get the current absolute URL in Ruby on Rails? - wilburkzw - 07-18-2023

url_for(params)

And you can easily add some new parameter:

url_for(params.merge(:tag => "lol"))