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

1 Answer 1

0

You could do something like this:

@test=cookies.permanent.signed[:remember_token] unless cookies.permanent.signed[:remember_token].nil?
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.