0

I am trying to set up user authentication in my ruby on rails app. I have the following code in app/controllers/application_controller.rb. Code fails when I try to reference the remember_token cookie before it has been set. How do I fix this? Attempted to do it with cookies.has_key(:remember_token) (see below) which failed because cookies is not a hash (I think).

  protect_from_forgery
include SessionsHelper
#before_filter :authenticate 

def authenticate
    @test={:email=>"dummy", :password=>"dummy"}
    @test=cookies.permanent.signed[:remember_token] if cookies.permanent.signed.has_key(:remember_token)==true

    if User.authenticate(@test[:email], @test[:password])[:allow]==false
        redirect_to :controller=>'sessions', :action=>'new'
    end

end
Evan V
  • 1,837
  • 1
  • 12
  • 10

1 Answers1

0

You could do something like this:

@test=cookies.permanent.signed[:remember_token] unless cookies.permanent.signed[:remember_token].nil?
Michael Frederick
  • 16,664
  • 3
  • 43
  • 58