Devise: Error: 'authenticable_salt returned nil for the User model'

Created on 10 Feb 2012  ·  11Comments  ·  Source: heartcombo/devise

I'm using rails 3.1.3 and just upgraded devise from 1.5.3 to 2.0.1. I re-generated the initializer so all properties have their default values. Now I'm getting this error when trying to login user:

 authenticable_salt returned nil for the User model. In order to use rememberable, you must ensure a password is always set or implement rememberable_value in your model with your own logic.

I don't have the standard DB-backed configuration because I'm using a custom authentication strategy via 3rd-party web-service. I tried adding authenticable_salt column to users table but that doesn't help as it's not being assigned anywhere and is always nil. If I really need to override the rememberable_value method, what should I put in it? Is there an example implementation? Please, I need some guidance in resolving this. Thank you.

Most helpful comment

If you use Devise master, everything should work by simply defining a remember_token column.

All 11 comments

If I just add an empty method rememberable_value it passes, but what's the way to do this correctly?

You need to create a database field, it could be the remember_token from previous devise versions. Then just do this:

before_create :remember_value

def remember_value
self.remember_token ||= Devise.friendly_token
end

Or something like that. I am on iPhone, so I can't enter more details. :(

s/remember_value/rememberable_value

Ok, that works. Thanks for such a quick help!

Hello. Actually the code above:

before_create :remember_value
def remember_value
  self.remember_token ||= Devise.friendly_token
end

doesn't work for remembering user sessions. After user restarts the browser devise asks to login again. Could you give any other ideas?

If you use Devise master, everything should work by simply defining a remember_token column.

Do you mean I don't need to use the above code anymore? If I just remove it I get the error:

authenticable_salt returned nil for the User model. In order to use rememberable, you must ensure a password is always set or implement rememberable_value in your model with your own logic.

I'm on devise 2.0.2.

Please use master branch, from git.

Works, thanks!

I'm using devise 2.1.0. I was getting the same error and was able to get rid of it by adding a remember_token column to the database.
However, although there is no error now, the cookie is not being saved. Do I have to do anything else apart from adding remember_token to the DB?
Thanks.

devise 2.2.1, same error when authenticated with third party service, cause the password was empty.

Was this page helpful?
0 / 5 - 0 ratings