我最近升级到了Rails 5升级后,修复通常的东西,我的应用程序运行正常,服务响应。
尽管我的测试套件通过了94%的覆盖率,但在执行实际请求时,控制器在声明请求是200 OK后崩溃。
看起来堆栈跟踪并没有指向我的应用程序中的任何代码,而是指向Actionpack中的某些内容。
这是我的错误配置,还是Rails5中的合法错误?
在141ms内完成200 OK(视图:2.2ms |活动记录:124.9ms)

    NoMethodError (undefined method `id' for {}:Hash):

    actionpack (5.0.0.1) lib/action_dispatch/request/session.rb:70:in `id'
    rack (2.0.1) lib/rack/session/abstract/id.rb:341:in `commit_session'
    rack (2.0.1) lib/rack/session/abstract/id.rb:224:in `context'
    rack (2.0.1) lib/rack/session/abstract/id.rb:216:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/cookies.rb:613:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
    activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/callbacks.rb:36:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
    railties (5.0.0.1) lib/rails/rack/logger.rb:36:in `call_app'
    railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `block in call'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `block in tagged'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:26:in `tagged'
    activesupport (5.0.0.1) lib/active_support/tagged_logging.rb:70:in `tagged'
    railties (5.0.0.1) lib/rails/rack/logger.rb:24:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/request_id.rb:24:in `call'
    rack (2.0.1) lib/rack/method_override.rb:22:in `call'
    rack (2.0.1) lib/rack/runtime.rb:22:in `call'
    activesupport (5.0.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/executor.rb:12:in `call'
    actionpack (5.0.0.1) lib/action_dispatch/middleware/static.rb:136:in `call'
    rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
    rack (2.0.1) lib/rack/sendfile.rb:111:in `call'
    railties (5.0.0.1) lib/rails/engine.rb:522:in `call'
    thin (1.7.0) lib/thin/connection.rb:86:in `block in pre_process'
    thin (1.7.0) lib/thin/connection.rb:84:in `catch'
    thin (1.7.0) lib/thin/connection.rb:84:in `pre_process'
    thin (1.7.0) lib/thin/connection.rb:53:in `process'
    thin (1.7.0) lib/thin/connection.rb:39:in `receive_data'
    eventmachine (1.2.1) lib/eventmachine.rb:194:in `run_machine'
    eventmachine (1.2.1) lib/eventmachine.rb:194:in `run'
    thin (1.7.0) lib/thin/backends/base.rb:73:in `start'
    thin (1.7.0) lib/thin/server.rb:162:in `start'
    rack (2.0.1) lib/rack/handler/thin.rb:22:in `run'
    rack (2.0.1) lib/rack/server.rb:296:in `start'
    railties (5.0.0.1) lib/rails/commands/server.rb:79:in `start'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:90:in `block in server'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:85:in `tap'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:85:in `server'
    railties (5.0.0.1) lib/rails/commands/commands_tasks.rb:49:in `run_command!'
    railties (5.0.0.1) lib/rails/commands.rb:18:in `<top (required)>'
    bin/rails:4:in `require'
    bin/rails:4:in `<main>'

最佳答案

我发现了问题在Rails 4天的应用程序中,我set request.session_options to {}看起来它不再是Rails 5中的散列我现在用reset_session代替request.session_options = {}

关于ruby-on-rails - 升级到Rails 5时出现新错误:NoMethodError({}:哈希的未定义方法'id'),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40854937/

10-13 09:26