0

これは本当に奇妙だと思うので、誰かが私を助けてくれることを願っています。私はDeviseを使用しており、ユーザーモデルを次のように定義しています:

class User < ActiveRecord::Base
    devise :database_authenticatable,
        :registerable,
        :token_authenticatable,
        :recoverable,
        :rememberable,
        :trackable,
        :validatable

        # Setup accessible (or protected) attributes for your model
        attr_accessible :email, :password, :password_confirmation
        attr_accessible :authentication_token
    en

新しいユーザーをサインアップしようとすると、次のエラーが表示されます。

ArgumentError

これは、他の情報を提供しないため、あまり役に立ちません。

パラメータは次のとおりです。

{"utf8"=>"✓",
"authenticity_token"=>"9VwmXYwBHEvdDxuPmyHu6tjcKeM6QoBtz6Y4ipBTtjQ=",
"user"=>{"email"=>"jeremy@[redacted].ca",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up"}

以下はスタック トレースです。他の誰かが理解できることを願っています。

bcrypt-ruby (3.0.1) lib/bcrypt.rb:160:in `create'
devise (2.2.3) lib/devise/models/database_authenticatable.rb:110:in `password_digest'
devise (2.2.3) lib/devise/models/database_authenticatable.rb:37:in `password='
activerecord (3.2.12) lib/active_record/attribute_assignment.rb:85:in `block in assign_attributes'
activerecord (3.2.12) lib/active_record/attribute_assignment.rb:78:in `each'
activerecord (3.2.12) lib/active_record/attribute_assignment.rb:78:in `assign_attributes'
activerecord (3.2.12) lib/active_record/base.rb:497:in `initialize'
devise (2.2.3) lib/devise/models/registerable.rb:20:in `new'
devise (2.2.3) lib/devise/models/registerable.rb:20:in `new_with_session'
devise (2.2.3) app/controllers/devise/registrations_controller.rb:87:in `build_resource'
devise (2.2.3) app/controllers/devise/registrations_controller.rb:13:in `create'
actionpack (3.2.12) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:167:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.2.12) lib/active_support/callbacks.rb:436:in `_run__2695083164076933069__process_action__522201399773442049__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `block in instrument'
activesupport (3.2.12) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (3.2.12) lib/active_support/notifications.rb:123:in `instrument'
actionpack (3.2.12) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.2.12) lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
activerecord (3.2.12) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (3.2.12) lib/abstract_controller/base.rb:121:in `process'
actionpack (3.2.12) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.12) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.12) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:36:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/mapper.rb:42:in `call'
journey (1.0.4) lib/journey/router.rb:68:in `block in call'
journey (1.0.4) lib/journey/router.rb:56:in `each'
journey (1.0.4) lib/journey/router.rb:56:in `call'
actionpack (3.2.12) lib/action_dispatch/routing/route_set.rb:601:in `call'
warden (1.2.1) lib/warden/manager.rb:35:in `block in call'
warden (1.2.1) lib/warden/manager.rb:34:in `catch'
warden (1.2.1) lib/warden/manager.rb:34:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.5) lib/rack/etag.rb:23:in `call'
rack (1.4.5) lib/rack/conditionalget.rb:35:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.5) lib/rack/session/abstract/id.rb:210:in `context'
rack (1.4.5) lib/rack/session/abstract/id.rb:205:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/cookies.rb:341:in `call'
activerecord (3.2.12) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.12) lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `_run__1001537658589897327__call__4072859572188315975__callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.12) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.12) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.12) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.12) lib/rails/engine.rb:479:in `call'
railties (3.2.12) lib/rails/application.rb:223:in `call'
railties (3.2.12) lib/rails/railtie/configurable.rb:30:in `method_missing'
4

1 に答える 1

3

問題は、config.stretchesinの値config/initializers/devise.rbが高すぎることです (31 を超えることはできません)。より低い値に変更すると、再び機能します。

それで、どうやってこれを理解したのですか?方法は次のとおりです。

ArgumentErrorスタック トレースから、 bcrypt-ruby でをスローする関数は次のとおりであることがわかります。

def create(secret, options = { :cost => BCrypt::Engine::DEFAULT_COST })
    raise ArgumentError if options[:cost] > 31
    Password.new(BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(options[:cost]), options[:cost]))
end

わかりました。問題は、Devise が 31 (最大許容値) よりも高いコストを送信していることです。Devise 呼び出しを見てみましょう (再びスタック トレースから):

def password_digest(password)
    ::BCrypt::Password.create("#{password}#{self.class.pepper}", :cost => self.class.stretches).to_s
end

そして、それが私たちが問題を見つける方法です。:)

于 2013-03-03T17:11:28.057 に答える