2011-08-03 54 views
10

我試圖用mongoid而不是主動型的Mongoid和has_secure_password

class User 
    include Mongoid::Document 
    include ActiveModel::SecurePassword 
    has_secure_password 
    validates_presence_of :password, :on => :create 
    attr_accessor :email, :password, :password_confirmation 
    field :email, :type => String 
    field :password_digest, :type => String 
end 

問題password_digest不被bycrypt公認的積極典範http://railscasts.com/episodes/270-authentication-in-rails-3-1

感謝

用Rails 3.1認證

回答

3

has_secure_password 

field :password_digest, :type => String 
+7

這不是正確的答案。 Adam需要像下面指出的那樣包含ActiveModel :: SecurePassword。 –

32

對於任何人誰是有興趣的,對於使用has_secure_password與Mongoid最起碼的要求是簡單的ActiveModel::SecurePassword在模型中納入。

class User 
    include Mongoid::Document 
    include ActiveModel::SecurePassword 

    field :username 
    field :password_digest 

    has_secure_password 
end 

Article