我跟着這是極好的,但是指導,當我添加has_secure_password到我的用戶模型: 類用戶<的ActiveRecord :: Base的 attr_accessible :姓名,:電子郵件:密碼:password_confirmation has_secure_password邁克爾·哈特爾教程第6章:錯誤bcrypt_ext.bundle:[BUG]分段故障
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
,然後嘗試通過鐵軌控制檯添加用戶:
1.9.3-p125 :001 > User.create(name: "Michael Hartl", email: "[email protected]",
1.9.3-p125 :002 > password: "foobar", password_confirmation: "foobar")
我收到與開始一個非常漫長的錯誤消息:
/Users/username/.rvm/gems/[email protected]/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.bundle: [BUG] Segmentation fault ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
-- Control frame information -----------------------------------------------
c:0058 p:-17575139500290 s:0220 b:0220 l:000219 d:000219 TOP
c:0057 p:---- s:0218 b:0218 l:000217 d:000217 CFUNC :require
,並繼續有更多的行...
如果我拿出「has_secure_password」從user.rb並嘗試創建相同的用戶上面我收到以下錯誤:
ActiveRecord::UnknownAttributeError: unknown attribute: password
最後,如果我再插入「attr_accessor:密碼:password_confirmation」到模型中,我可以成功添加用戶,但是,password_digest爲零。
我知道我做錯了什麼,但是,我很難過。