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

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.
48e8d4452262d3667502835a54e8b249?d=identicon&s=25 Chris Earle (Guest)
on 2007-04-09 18: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
if
they exist

If they don't exist, I want to redirect the user to the login page --
which
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()
        useridcookie=cookies[:UserID]
        usersessioncookie=cookies[:usersession]
        if (!useridcookie)
          redirect_to "http://loginpage.html"
        end
        if (!usersessioncookie)
          redirect_to http://loginpage.html
        end
  end
end


-----

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


Any help much appreciated!






--
Chris
8310c5a7c769345114597bcdef111488?d=identicon&s=25 Ben Munat (Guest)
on 2007-04-09 20: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
happening...

b

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.