Skip to content

Instantly share code, notes, and snippets.

@soey
Created December 4, 2013 20:15
Show Gist options
  • Save soey/7794712 to your computer and use it in GitHub Desktop.
Save soey/7794712 to your computer and use it in GitHub Desktop.
monkey patch devise token authenticable to survive baked in cookies..
# monkey patch devise token authenticable to have tokens surviving in cookies
require 'securerandom'
module Devise
module Models
module TokenAuthenticatable
module ClassMethods
# Generate a token checking if one does not already exist in the database.
def authentication_token
loop do
token = SecureRandom.hex(32)
break token unless to_adapter.find_first({ :authentication_token => token })
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment