轨道上的红宝石 - 注册时设计宝石出错



我在使用 Devise 注册时遇到错误。我正在从之前设置的基于会话的身份验证系统切换到 Devise。

我安装了 Devise 并在我的模型中安装了它:

devise :database_authenticatable,  :registerable, :confirmable,
       :recoverable, :rememberable, :trackable, :validatable

这是我的迁移:

class AddDeviseUserTable < ActiveRecord::Migration
  def self.up
    create_table(:users) do |t|
      t.database_authenticatable :null => false
      t.recoverable
      t.rememberable
      t.trackable
      t.confirmable
      t.encryptable
      t.timestamps
    end
    add_column :users, :name, :string
    add_index :users, :email,                :unique => true
    add_index :users, :reset_password_token, :unique => true
    # add_index :users, :confirmation_token,   :unique => true
    # add_index :users, :unlock_token,         :unique => true
    # add_index :users, :authentication_token, :unique => true
  end
  def self.down
    drop_table :users
  end
end

我的路线中也有这个:

root :to => "videos#index"
devise_for :users
resources :users do
  member do
    get :following, :followers
  end
end

注册时遇到的错误是:

NameError in Devise/registrationsController#create
undefined local variable or method `encrypt_new_password' for #<User:0x1032a8cb8>

以下是完整的跟踪:

activemodel (3.0.4) lib/active_model/attribute_methods.rb:364:in `method_missing'
activerecord (3.0.4) lib/active_record/attribute_methods.rb:46:in `method_missing'
activesupport (3.0.4) lib/active_support/callbacks.rb:419:in `_run_save_callbacks'
activerecord (3.0.4) lib/active_record/callbacks.rb:277:in `create_or_update'
activerecord (3.0.4) lib/active_record/persistence.rb:39:in `save'
activerecord (3.0.4) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.4) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.4) lib/active_record/transactions.rb:240:in `save'
activerecord (3.0.4) lib/active_record/transactions.rb:292:in `with_transaction_returning_status'
activerecord (3.0.4) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.4) lib/active_record/transactions.rb:207:in `transaction'
activerecord (3.0.4) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
activerecord (3.0.4) lib/active_record/transactions.rb:240:in `save'
activerecord (3.0.4) lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
activerecord (3.0.4) lib/active_record/transactions.rb:239:in `save'
devise (1.3.4) app/controllers/devise/registrations_controller.rb:16:in `create'
actionpack (3.0.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.4) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.4) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.4) lib/abstract_controller/callbacks.rb:18:in `process_action'
activesupport (3.0.4) lib/active_support/callbacks.rb:445:in `_run__1732029701__process_action__1623385099__callbacks'
activesupport (3.0.4) lib/active_support/callbacks.rb:409:in `send'
activesupport (3.0.4) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.4) lib/active_support/callbacks.rb:93:in `send'
activesupport (3.0.4) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.4) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
activesupport (3.0.4) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.4) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.4) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.4) lib/action_controller/metal/rescue.rb:17:in `process_action'
actionpack (3.0.4) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.4) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.4) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.4) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.4) lib/action_controller/metal.rb:178:in `action'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:27:in `call'
actionpack (3.0.4) lib/action_dispatch/routing/mapper.rb:35:in `call'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in `call'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:93:in `recognize'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:89:in `optimized_each'
rack-mount (0.6.13) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.4) lib/action_dispatch/routing/route_set.rb:492:in `call'
warden (1.0.4) lib/warden/manager.rb:35:in `call'
warden (1.0.4) lib/warden/manager.rb:34:in `catch'
warden (1.0.4) lib/warden/manager.rb:34:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.1) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.4) lib/active_record/query_cache.rb:32:in `call'
activerecord (3.0.4) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.4) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.4) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/callbacks.rb:46:in `call'
activesupport (3.0.4) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.4) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.1) lib/rack/sendfile.rb:107:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.4) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.4) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.4) lib/active_support/cache/strategy/local_cache.rb:72:in `call'

为什么我会收到此错误?我该如何解决?

Devise 源代码中没有encrypt_new_password方法,所以我怀疑当您从以前的身份验证系统切换到 Device 时,这种方法被抛在了后面。我会在您的应用程序代码中搜索字符串encrypt_new_password,看看你能找到什么。

可能是用户模型中需要更多清理的内容。特别是在您的用户模型中查找回调之前和/或之后的任何过时的东西,因为故障发生在调用User#save 期间。

相关内容

  • 没有找到相关文章

最新更新