How do I check if request.HTTP_REFERER is defined?

173 views
Skip to first unread message

desbest

unread,
Oct 31, 2012, 8:53:29 PM10/31/12
to ram...@googlegroups.com
This may sound like a foolish question but when I use defined? it doesn't work and if I just use !request.HTTP_REFERER.nil? or if request.REFERRER
it either doesn't work or I get an exception error saying that it's an undefined method.

For all other variables like the user.username one it works, but not on request.

Yorick Peterse

unread,
Nov 1, 2012, 6:48:47 AM11/1/12
to ram...@googlegroups.com
Desbest,

You can simply check this as following:

if request['HTTP_REFERER']
# Do something with the referrer header.
else
# Do something else.
end

Yorick
> --
> You received this message because you are subscribed to the Google
> Groups "Ramaze" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/ramaze/-/WdawS4Dbzh8J.
> To post to this group, send email to ram...@googlegroups.com.
> To unsubscribe from this group, send email to
> ramaze+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ramaze?hl=en.

tynamite

unread,
Nov 1, 2012, 7:36:22 AM11/1/12
to ram...@googlegroups.com
I tried that just now and it doesn't work.
Here's a gif screencast to show you how what is happening is different from expected behaviour.



On 1 November 2012 10:48, Yorick Peterse <yorick...@gmail.com> wrote:
Desbest,

You can simply check this as following:

    if request['HTTP_REFERER']
      # Do something with the referrer header.
    else
      # Do something else.
    end

Yorick

On 01/11/12 01:53, desbest wrote:
This may sound like a foolish question but when I use defined? it
doesn't work and if I just use !request.HTTP_REFERER.nil? or if
request.REFERRER
it either doesn't work or I get an exception error saying that it's an
undefined method.

For all other variables like the user.username one it works, but not on
request.


--
You received this message because you are subscribed to the Google
Groups "Ramaze" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/ramaze/-/WdawS4Dbzh8J.
To post to this group, send email to ram...@googlegroups.com.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/ramaze?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ramaze" group.
To post to this group, send email to ram...@googlegroups.com.
To unsubscribe from this group, send email to ramaze+unsubscribe@googlegroups.com.

Yorick Peterse

unread,
Nov 1, 2012, 7:55:25 AM11/1/12
to ram...@googlegroups.com
Desbest,

My mistake, it's located in `request.env['HTTP_REFERER']` and not
`request['HTTP_REFERER']`.

Yorick

tynamite

unread,
Nov 1, 2012, 8:47:51 AM11/1/12
to ram...@googlegroups.com
Thank you, this works!


John

unread,
Nov 2, 2012, 4:25:08 AM11/2/12
to ram...@googlegroups.com
Perhaps off-topic, but in this respect if you need to create a 'stack' of requests for redirection reasons

e'g'; lets say someone arrives in page A, then is redirected to Login page B, then is redirected to survey C, then back to A 

what is the best way to do so?

/pagojo

Yorick Peterse

unread,
Nov 2, 2012, 4:57:34 AM11/2/12
to ram...@googlegroups.com
John,

In this case you'd probably want to store this in the user's session.
Something like the following could be a start for this:

class MainController < Ramaze::Controller
before_all do
if request.env['HTTP_REFERER']
session[:redirects] ||= []
session[:redirects] << request.env['HTTP_REFERER']
end
end
end

Yorick

John

unread,
Nov 27, 2012, 3:57:38 AM11/27/12
to ram...@googlegroups.com
Thanks, I thought there might be a more sophisticated way in the framework that i've missed :-)

/pagojo 
Reply all
Reply to author
Forward
0 new messages