开发者

Getting "undefined method `password' for #<User:0x2b95caea8590>" with Authlogic

I realize there's a nearly identical question about this here but the fix there did not fix my problem.

My Authlogic is working in my development environment but not in my production environment. Below is the error I'm getting.

Started GET "/users/new" for 71.205.20开发者_如何学JAVA7.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'

I didn't misspell any of the database columns, I'm already doing acts_as_authentic and I have restarted my server, so I'm not sure what else to try. It seems like it must be something to do with my database but my database structure seems to be identical.


Database password field (and/or salt field) may not match any of the defaults!!!

I've had this problem twice now and in both cases it was tricky because of two things:

1) The message "undefined method 'password' really (often) means password field not found in database using defaults.

2) The location to ADD your database field for password (or salt for that matter) is NOT anywhere in your applications directory, it in your ruby gem directory, something like ~/.gem/ruby/1.8/gems/authlogic-2.1.6/lib/authlogic/acts_as_authentic !

The field to change is password.rb. Add your field name(s) in to the list, e.g. i added pd_hashed changed:

module Config # The name of the crypted_password field in the database. # # * Default: :crypted_password, :encrypted_password, :password_hash, or :pw_hash # * Accepts: Symbol def crypted_password_field(value = nil) rw_config(:crypted_password_field, value, first_column_to_exist(nil, :pd_hashed, :crypted_password, :encrypted_password, :password_hash, :pw_hash)) end

Do the same for the salt field.

Restart and this may help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜