我正在尝试使用更改为支持 bcrypt 密码的模型,就像这样
require 'bcrypt'
class User < ActiveRecord::Base
# users.password_hash in the database is a :string
include BCrypt
def password
@password ||= Password.new(password_hash)
end
def password=(new_password)
@password = Password.create(new_password)
self.password_hash = @password
end
end
我在脚手架之后添加了这个,希望密码和密码 = 足以让它继续运行,使用这个,但是它不起作用,form_for() 等不起作用,我收到错误:
ActionView::Template::Error (invalid hash):
2012-06-07T12:45:20+00:00 app[web.1]: 17: </div>
2012-06-07T12:45:20+00:00 app[web.1]: 18: <div class="field">
2012-06-07T12:45:20+00:00 app[web.1]: 19: <%= f.label :password %><br />
2012-06-07T12:45:20+00:00 app[web.1]: 20: <%= f.text_field :password %>
2012-06-07T12:45:20+00:00 app[web.1]: 21: </div>
2012-06-07T12:45:20+00:00 app[web.1]: 22: <div class="field">
2012-06-07T12:45:20+00:00 app[web.1]: 23: <%= f.label :email %><br />
有谁知道我怎样才能完成这项工作,我是 Rails 的新手
这是按要求在新功能完整回溯中:
2012-06-12T18:23:57+00:00 app[web.1]: ActionView::Template::Error (invalid hash):
2012-06-12T18:23:57+00:00 app[web.1]: 19: <%= f.label :password %><br />
2012-06-12T18:23:57+00:00 app[web.1]: 18: <div class="field">
2012-06-12T18:23:57+00:00 app[web.1]: 17: </div>
2012-06-12T18:23:57+00:00 app[web.1]: 20: <%= f.text_field :password %>
2012-06-12T18:23:57+00:00 app[web.1]: 22: <div class="field">
2012-06-12T18:23:57+00:00 app[web.1]: 23: <%= f.label :email %><br />
2012-06-12T18:23:57+00:00 app[web.1]: app/models/user.rb:19:in `new'
2012-06-12T18:23:57+00:00 app[web.1]: 21: </div>
2012-06-12T18:23:57+00:00 app[web.1]: app/models/user.rb:19:in `password'
2012-06-12T18:23:57+00:00 app[web.1]: app/views/users/_form.html.erb:20:in `block in _app_views_users__form_html_erb__2064609863987267967_31546180'
2012-06-12T18:23:57+00:00 app[web.1]: app/views/users/_form.html.erb:1:in `_app_views_users__form_html_erb__2064609863987267967_31546180'
2012-06-12T18:23:57+00:00 app[web.1]: app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___1991359801167056023_31763940'
2012-06-12T18:23:57+00:00 app[web.1]: app/controllers/users_controller.rb:251:in `new'