Forum: Ruby on Rails How do I get the the full URL of an incoming request

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Gustav P. (Guest)
on 2006-01-30 19:07
Hey,

Is is possible to get the full URL
('http://www.sender-domain.com/links/list.html')

from where a user was sent to my site
(www.my-domain.com/controller/action) e.g. by clicking on a link? (I
read about something called a 'request' object, I don't know what it is
or does, is that what I'm looking for?

I'm very new to Rails so I'd appreciate any help!!

Thanks,
Gustav

e-mail: removed_email_address@domain.invalid

"Touched by His noodly appendage",
 -- www.venganza.org
Alex Y. (Guest)
on 2006-01-30 19:16
(Received via mailing list)
gustav paul wrote:
> Hey,
>
> Is is possible to get the full URL
> ('http://www.sender-domain.com/links/list.html')
>
> from where a user was sent to my site
> (www.my-domain.com/controller/action) e.g. by clicking on a link? (I
> read about something called a 'request' object, I don't know what it is
> or does, is that what I'm looking for?
It should be available in the controller as
@request.env["HTTP_REFERER"].
Dominique P. (Guest)
on 2006-01-30 19:50
Confirmed!

In a simple controller action, I put:
@referringPageURL = @request.env["HTTP_REFERER"]

In the corresponding view I entered:
referring page = <%= @referringPageURL %>

To confirm, I added a standard HTML link to the page in the
/public/index.html file, and I also cloned that file as
/public/index2.html and also followed the link from there.

Note that request.env["HTTP_REFERER"] also seems to work.

http://api.rubyonrails.org/classes/ActionControlle... hints that
to get the IP address where the request came from, you can use
request.env["REMOTE_IP"] in the controller.

Hope this helps!

Thanks,
Dominique


Alex Y. wrote:
> gustav paul wrote:
>> Hey,
>>
>> Is is possible to get the full URL
>> ('http://www.sender-domain.com/links/list.html')
>>
>> from where a user was sent to my site
>> (www.my-domain.com/controller/action) e.g. by clicking on a link? (I
>> read about something called a 'request' object, I don't know what it is
>> or does, is that what I'm looking for?
> It should be available in the controller as
> @request.env["HTTP_REFERER"].
Bob S. (Guest)
on 2006-01-30 20:14
(Received via mailing list)
request.remote_ip() works better as it handles proxied IPs also.

Again, HTTP_REFERER is not dependable. Some clients send it some don't.

Bob S.
http://www.railtie.net/
Bob S. (Guest)
on 2006-01-30 20:26
(Received via mailing list)
Unfortunately, HTTP_REFERER is useless nowadays. There is no stable
method
of getting that information.

Bob S.
http://www.railtie.net/
Eric G. (Guest)
on 2006-10-19 14:02
so whats the best way to handle a login controller that uses a before
filter to catches users who arent logged in.

How do you enable the user to go to the page they were trying to get to?

Ive been having problems with request.env["HTTP_REFERER"] as well

When I have a complex url like /books?id=5&c=4

then it works, but if it is simple like

/books, it doesnt work correctly. Anyone figure this out?
Chris M. (Guest)
on 2006-10-19 16:07
(Received via mailing list)
Eric G. wrote:
>
> /books, it doesnt work correctly. Anyone figure this out?

I do this by having a before_filter on the protected page that stores
the path of that page in a session variable, using request.path:

session[:requested_page] = request.path
flash[:notice] = "Please log in first."
redirect_to(:controller => 'login')

Then when they log in successfully, you can just do

redirect_to(session[:requested_page])

It's handled every URL I've thrown at it so far! It also feels a bit
more reliable than trusting the HTTP_REFERER environment variable.

Chris
Jason N. (Guest)
on 2006-10-19 16:13
(Received via mailing list)
Have you tried using request.parameters? Way sweeter as it gives you the
same hash that was originally generated form your routes.
Eric G. (Guest)
on 2006-10-20 03:26
I tried all the methods listed in this thread, none of them works
correctly with IE 6. For example if my url is /books/view?book=1, the
best that any method returns is

"books/view"

In other words, the parameters are left out.

Jason N. wrote:
> Have you tried using request.parameters? Way sweeter as it gives you the
> same hash that was originally generated form your routes.
Eric G. (Guest)
on 2006-10-20 14:43
 i have the following url im trying to
save:

http://127.0.0.1:3000/photos/view?book=1&id=2

The problem is, when I use url_for {request.parameters},

it doesnt include the ?book=1&id=2 part. However, when I do "puts
request.parameters[:id]", I get "2"

Whats going on here? Thanks in advance...
Thorsten L (Guest)
on 2006-10-20 15:13
(Received via mailing list)
i cant look at my code at home right now as i'm in the office, but i
think i used this :

redirect_to request.request_uri
This topic is locked and can not be replied to.