Ruby on rails 获得;未定义的方法`密码';对于#<;用户:0x2b95caea8590>&引用;用Authlogic

Ruby on rails 获得;未定义的方法`密码';对于#<;用户:0x2b95caea8590>&引用;用Authlogic,ruby-on-rails,ruby-on-rails-3,authentication,passwords,authlogic,Ruby On Rails,Ruby On Rails 3,Authentication,Passwords,Authlogic,我意识到关于这个问题有一个几乎相同的问题,但是那里的修复并没有解决我的问题 我的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) Render

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

我的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'
于2011年2月22日星期二19:24:49-0800在71.205.207.120开始获取“/users/new”
由UsersController处理#新为HTML
呈现用户/_form.html.erb(19.3ms)
布局/应用程序中的呈现用户/new.html.erb(21.6ms)
在38毫秒内完成
ActionView::Template::Error(未定义#的“password”方法):
21:   
22:   
23:
24: 25: 26: 27:
app/views/users/_-form.html.erb:24:in`_-app\u-views\u-users\u-form\u-html\u-erb\u 1397135998\u 23961177217120\u 1124190' app/views/users/_-form.html.erb:1:in`_-app\u-views\u-users\u-form\u-html\u-erb\u 1397135998\u 23961177217120\u 1124190' app/views/users/new.html.erb:3:in`_app\u views\u users\u new\u html\u erb\u 1081160896\u 23961177226000\u 0' app/controllers/users\u controller.rb:29:in'new'
我没有拼错任何数据库列,我已经在做
acts\u asu\u authentic
,并且我已经重新启动了我的服务器,所以我不确定还有什么可以尝试的。这似乎与我的数据库有关,但我的数据库结构似乎相同。

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

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

1) 消息“undefined method'password”实际上(通常)意味着使用默认值在数据库中找不到密码字段

2) 为密码(或salt)添加数据库字段的位置不在应用程序目录中的任何位置,而是在ruby gem目录中,类似于~/.gem/ruby/1.8/gems/authlogic-2.1.6/lib/authlogic/acts_as_authentic

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

模块配置 #数据库中加密的_密码字段的名称。 # #*默认值::加密的\u密码、:加密的\u密码、:密码\u哈希或:pw\u哈希 #*接受:符号 def加密密码字段(值=nil) rw_config(:crypted_password_字段,值,第一个_列_to_存在(nil,:pd_散列,:crypted_password,:encrypted_password,:password_散列,:pw_散列)) 结束

对盐田也要这样做


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

您迁移了生产服务器上的数据库吗?是的,我验证了显示了我的数据库更改。重新启动生产服务器怎么样?不是操作系统服务器,只是rails服务。试着在生产服务器上运行rails控制台,然后运行以下命令:User.new.methods.grep/^password/是否返回:password方法有吗?@CalebHC:没有。在开发中有,但在生产中没有。对下一步做什么有什么建议吗?