Skip to content

Instantly share code, notes, and snippets.

@spockz
Created March 20, 2012 15:36
Show Gist options
  • Save spockz/2137160 to your computer and use it in GitHub Desktop.
Save spockz/2137160 to your computer and use it in GitHub Desktop.
Token.user_id = NILL, why? What am I doing wrong?
class User
include MongoMapper::Document
safe
key :email, String
key :username, String
key :first_name, String
key :last_name, String
key :encrypted_password, String
key :password_salt, String
key :reset_password_token, String
key :remember_token, String
key :remember_created_at, Time
key :sign_in_count, Integer
key :current_sign_in_at, Time
key :current_sign_in_ip, String
key :last_sign_in_at, Time
key :last_sign_in_ip, String
timestamps!
many :tokens
attr_accessor :login
attr_accessible :username, :email, :password, :password_confirmation, :login
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:token_authenticatable, :authentication_keys => [:login]
def self.find_for_database_authentication(conditions)
login = conditions.delete(:login).downcase
where('$or' => [{:username => login}, {:email => login}]).first
end
end
class Token
include MongoMapper::Document
key :token, String, :required => true
key :date, Time, :required => true
key :comment, String
belongs_to :user
end
@token = Token.new(params[:token])
@token.token = "aaaa"
@token.date = Time.now()
@token.user = current_user
puts current_user.username # => Outputs the username correctly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment