Forum: Ruby on Rails redirecting if cookie doesn't exist

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris E. (Guest)
on 2007-04-09 20:39
(Received via mailing list)
Hi all,

I cannot get this to work at all .. it never does the redirect.

I have two authentication cookies set ... Rails reads thier values fine
they exist

If they don't exist, I want to redirect the user to the login page --
is not a rails controller/model ....(single sign on location)

I figured I'd add the code to the application_helper ... so that I could
reference it in all my views.

module ApplicationHelper

  def ifLoggedIn()
        if (!useridcookie)
          redirect_to "http://loginpage.html"
        if (!usersessioncookie)
          redirect_to http://loginpage.html


in my view (list.rhtml), I call <% ifLoggedIn() %>
right at the top

Any help much appreciated!

Ben M. (Guest)
on 2007-04-09 22:40
(Received via mailing list)
Well, in the example you posted, you don't have quotes around the second
"http://loginpage.html/"... though maybe that's just a error in copying.

Other than that, maybe try some logging in there to see what's


PS: Oh, one more thing... I think most people usually do their logged in
check in the ApplicationController (application.rb) and hook it up as a
before_filter for all their actions. That way you won't have to put
ifLoggedIn in every single view.
This topic is locked and can not be replied to.