使用Authlogic获取“<user:0x2b95caea8590>”的“未定义方法`密码”</user:0x2b95caea8590>

时间:2011-02-23 03:29:51

标签: ruby-on-rails ruby-on-rails-3 authentication passwords authlogic

我意识到关于这个here的问题几乎完全相同,但是那里的修复并没有解决我的问题。

我的Authlogic正在我的开发环境中工作,但不在我的生产环境中。以下是我得到的错误。

Started GET "/users/new" for 71.205.207.120 at Tue Feb 22 19:24:49 -0800 2011
  Processing by UsersController#new as HTML
Rendered users/_form.html.erb (19.3ms)
Rendered users/new.html.erb within layouts/application (21.6ms)
Completed   in 38ms

ActionView::Template::Error (undefined method `password' for #<User:0x2b95caea8590>):
    21:   </div>
    22:   <div class="field">
    23:     <%= f.label :password %><br />
    24:     <%= f.password_field :password %>
    25:   </div>
    26:   <div class="field">
    27:     <%= f.label :password_confirmation %><br />
  app/views/users/_form.html.erb:24:in `_app_views_users__form_html_erb___1397135998_23961177217120_1124190'
  app/views/users/_form.html.erb:1:in `_app_views_users__form_html_erb___1397135998_23961177217120_1124190'
  app/views/users/new.html.erb:3:in `_app_views_users_new_html_erb___1081160896_23961177226000_0'
  app/controllers/users_controller.rb:29:in `new'

我没有拼错任何数据库列,我已经在做acts_as_authentic并且我已经重新启动了我的服务器,所以我不确定还有什么可以尝试。似乎它必须与我的数据库有关,但我的数据库结构似乎是相同的。

1 个答案:

答案 0 :(得分:1)

数据库密码字段(和/或salt字段)可能与任何默认值都不匹配!!!

我现在已经有两次这个问题了,在这两种情况下都很棘手,因为有两件事:

1)消息“未定义方法'密码'确实(通常)表示使用默认值在数据库中找不到密码字段。

2)添加数据库字段以获取密码(或盐)的位置不在应用程序目录中的任何位置,在ruby gem目录中,如〜/ .gem / ruby​​ / 1.8 / gems / authlogic -2.1.6 / lib / authlogic / acts_as_authentic!

要更改的字段是password.rb。将您的字段名称添加到列表中,例如我添加了pd_hashed更改:

模块配置     #数据库中crypted_pa​​ssword字段的名称。     #     #*默认:: crypted_pa​​ssword,:encrypted_pa​​ssword,:password_hash或:pw_hash     #*接受:符号     def crypted_pa​​ssword_field(value = nil)       rw_config(:crypted_pa​​ssword_field,value,first_column_to_exist(nil,:pd_hashed,:crypted_pa​​ssword,:encrypted_pa​​ssword,:password_hash,:pw_hash))     端

对盐田做同样的事。

重启,这可能会有所帮助。