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?

#11
This works for Ruby on Rails 3.0 and should be supported by most versions of Ruby on Rails:

request.env['REQUEST_URI']
Reply

#12
Using Ruby 1.9.3-p194 and Ruby on Rails 3.2.6:

If **request.fullpath** doesn't work for you, try **request.env["HTTP_REFERER"]**

Here's my story below.

I got similar problem with detecting current URL (which is shown in address bar for user in her browser) for cumulative pages which combines information from different controllers, for example, `http://localhost:3002/users/1/history/issues`.

The user can switch to different lists of types of issues. All those lists are loaded via Ajax from different controllers/partials (without reloading).

The problem was to set the correct path for the back button in each item of the list so the back button could work correctly both in its own page and in the cumulative page *history*.

In case I use **request.fullpath**, it returns the path of last JavaScript request which is definitely not the URL I'm looking for.

So I used **request.env["HTTP_REFERER"]** which stores the URL of the last reloaded request.

Here's an excerpt from the partial to make a decision

- if request.env["HTTP_REFERER"].to_s.scan("history").length > 0
- back_url = user_history_issue_path(@user, list: "needed_type")
- else
- back_url = user_needed_type_issue_path(@user)
- remote ||= false
=link_to t("static.back"), back_url, :remote => remote
Reply

#13
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:

[To see links please register here]

users_path: /users




Reply

#14
if you want to be specific, meaning, you know the path you need:

link_to current_path(@resource, :only_path => false), current_path(@resource)
Reply

#15
In Rails 3 you can use

request.original_url

[To see links please register here]

Reply

#16
None of the suggestions here in the thread helped me sadly, except the one where someone said he used the debugger to find what he looked for.

I've created some custom error pages instead of the standard 404 and 500, but `request.url` ended in `/404` instead of the expected `/non-existing-mumbo-jumbo`.

What I needed to use was

request.original_url
Reply

#17
DEPRECATION WARNING: [Using #request_uri is deprecated][1]. Use fullpath instead.


[1]:

[To see links please register here]

Reply

#18
For rails 3 :

> request.fullpath
Reply

#19
request.env["REQUEST_URI"]

works in rails 2.3.4 tested and do not know about other versions.
Reply

#20
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}"
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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