manejo de cookies inexistentes en autenticación ruby ​​on rails

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

preguntado el 25 de agosto de 12 a las 00:08

1 Respuestas

Podrías hacer algo como esto:

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

Respondido 25 ago 12, 01:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.