Monday, February 21, 2011

problems with cookies

i'm using restful-authentication plugin with rails 2.3.8

i've problems with cookies store

i've put a logger instruction in this function for check the cookie:

 def send_remember_cookie!
      cookies[:auth_token] = {
        :value   => @current_user.remember_token,
        :expires => @current_user.remember_token_expires_at }  
      logger.error "--------------#{cookies[:auth_token].keys}"   
    end

But when i launch the program i receive this error:

undefined method `keys' for nil:NilClass

why?

How can i set the cookie?

thanks

From stackoverflow
  • The cookies object is an instance ApplicationController::CookieJar. It's almost like a Hash but the behavior of the [] and []= methods are not symmetric. The setter sets the cookie value for sending to the browser. The getter retrieves the value which comes back form the browser. Hence when you access it in your code having just set the outgoing value the incoming value will be unset. There some more info on this here

    Also did you intentionally mean to say cookie[:auth_token].keys or did you mean cookie.keys?

0 comments:

Post a Comment