gustav paul
2006-Jan-30 17:07 UTC
[Rails] How do I get the the full URL of an incoming request
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: gustav@psychohistorian.org "Touched by His noodly appendage", -- www.venganza.org -- Posted via http://www.ruby-forum.com/.
Alex Young
2006-Jan-30 17:15 UTC
[Rails] How do I get the the full URL of an incoming request
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"]. -- Alex
Bob Silva
2006-Jan-30 17:51 UTC
[Rails] How do I get the the full URL of an incoming request
Unfortunately, HTTP_REFERER is useless nowadays. There is no stable method of getting that information. Bob Silva http://www.railtie.net/ -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Alex Young Sent: Monday, January 30, 2006 9:16 AM To: rails@lists.rubyonrails.org Subject: Re: [Rails] How do I get the the full URL of an incoming request 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"]. -- Alex _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Dominique Plante
2006-Jan-30 17:53 UTC
[Rails] Re: How do I get the the full URL of an incoming request
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/ActionController/Base.html 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 Young 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"].-- Posted via http://www.ruby-forum.com/.
Bob Silva
2006-Jan-30 18:13 UTC
[Rails] Re: How do I get the the full URL of an incoming request
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 Silva http://www.railtie.net/ -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Dominique Plante Sent: Monday, January 30, 2006 9:51 AM To: rails@lists.rubyonrails.org Subject: [Rails] Re: How do I get the the full URL of an incoming request 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/ActionController/Base.html 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 Young 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"].-- Posted via http://www.ruby-forum.com/. _______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
Eric Gross
2006-Oct-19 10:02 UTC
Re: RE: How do I get the the full URL of an incoming request
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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Eric Gross wrote:> 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?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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jason Norris
2006-Oct-19 12:09 UTC
Re: How do I get the the full URL of an incoming request
Have you tried using request.parameters? Way sweeter as it gives you the same hash that was originally generated form your routes. Eric Gross wrote:> 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? > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 Norris wrote:> Have you tried using request.parameters? Way sweeter as it gives you the > same hash that was originally generated form your routes.-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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... -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---