Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 760 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I get the current absolute URL in Ruby on Rails?

#21
you can get absolute url by calling:

request.original_url

or

request.env['HTTP_REFERER']
Reply

#22
**Rails 4.0**

you can use `request.original_url`, output will be as given below example

get "/articles?page=2"

request.original_url # => "http://www.example.com/articles?page=2"

Reply

#23
To get the request URL without any query parameters.

def current_url_without_parameters
request.base_url + request.path
end
Reply

#24
**Rails 4**

Controller:

def absolute_url
request.base_url + request.original_fullpath
end

**Action Mailer Notable changes in [4.2 release][1]:**


link_to and url_for generate absolute URLs by default in templates, it is no longer needed to pass only_path: false. (Commit)

View:

If you use the `_url` suffix, the generated URL is absolute. Use `_path` to get a relative URL.


<%= link_to "Home", root_url %>


For More Details, go to:

[To see links please register here]



[1]:

[To see links please register here]

Reply

#25
You can use:

request.full_path

or

request.url

Hopefully it will resolve your problem.

Cheers

Reply

#26
You can either use

request.original_url
or

"#{request.protocol}#{request.host_with_port}"
to get the current URL.
Reply

#27
You can set a variable to `URI.parse(current_url)`, I don't see this proposal here yet and it works for me.
Reply

#28
You can add this [current_url](

[To see links please register here]

) method in the ApplicationController to return the current URL and allow merging in other parameters

#

[To see links please register here]

# + current_url( :page => 3 )
# =

[To see links please register here]

def current_url(overwrite={})
url_for :only_path => false, :params => params.merge(overwrite)
end


**Example Usage:**

current_url --> http://...
current_url(:page=>4) --> http://...&page=4
Reply

#29
For Rails 3.x and up:

#{request.protocol}#{request.host_with_port}#{request.fullpath}

For Rails 3.2 and up:

request.original_url

Because in rails 3.2 and up:

request.original_url = request.base_url + request.original_fullpath

For more info, plese visit

[To see links please register here]

Reply

#30
You can use the ruby method:

:root_url

which will get the full path with base url:

localhost:3000/bla
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through