1

我安装了hotwire-railsgem 并运行rails hotwire:install,这似乎工作正常。

当我从视图调用该方法turbo_stream_from "posts"时,我收到以下错误,我根本不明白。

undefined method `then' for "posts":String

在多个示例中,我看到一个字符串被传递给方法 turbo_stream_from,以识别流名称。我尝试检查 repo,但根据我对所见内容的了解,我没有找到太多东西。有人知道我可能会缺少哪些东西来完成这项工作吗?

turbo-rails (0.5.1) app/channels/turbo/streams/stream_name.rb:21:in `stream_name_from'
turbo-rails (0.5.1) app/channels/turbo/streams/stream_name.rb:19:in `block in stream_name_from'
turbo-rails (0.5.1) app/channels/turbo/streams/stream_name.rb:19:in `map'
turbo-rails (0.5.1) app/channels/turbo/streams/stream_name.rb:19:in `stream_name_from'
turbo-rails (0.5.1) app/channels/turbo/streams/stream_name.rb:13:in `signed_stream_name'
turbo-rails (0.5.1) app/helpers/turbo/streams_helper.rb:20:in `turbo_stream_from'
app/views/forms/index.html.haml:6
actionview (6.0.3.5) lib/action_view/base.rb:274:in `_run'
actionview (6.0.3.5) lib/action_view/template.rb:185:in `block in render'
activesupport (6.0.3.5) lib/active_support/notifications.rb:182:in `instrument'
actionview (6.0.3.5) lib/action_view/template.rb:385:in `instrument_render_template'
actionview (6.0.3.5) lib/action_view/template.rb:183:in `render'
actionview (6.0.3.5) lib/action_view/renderer/template_renderer.rb:58:in `block (2 levels) in render_template'
actionview (6.0.3.5) lib/action_view/renderer/abstract_renderer.rb:88:in `block in instrument'
activesupport (6.0.3.5) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.5) lib/active_support/notifications.rb:180:in `instrument'
actionview (6.0.3.5) lib/action_view/renderer/abstract_renderer.rb:87:in `instrument'
actionview (6.0.3.5) lib/action_view/renderer/template_renderer.rb:57:in `block in render_template'
actionview (6.0.3.5) lib/action_view/renderer/template_renderer.rb:65:in `render_with_layout'
actionview (6.0.3.5) lib/action_view/renderer/template_renderer.rb:56:in `render_template'
actionview (6.0.3.5) lib/action_view/renderer/template_renderer.rb:13:in `render'
actionview (6.0.3.5) lib/action_view/renderer/renderer.rb:61:in `render_template_to_object'
actionview (6.0.3.5) lib/action_view/renderer/renderer.rb:29:in `render_to_object'
actionview (6.0.3.5) lib/action_view/rendering.rb:117:in `block in _render_template'
actionview (6.0.3.5) lib/action_view/base.rb:304:in `in_rendering_context'
actionview (6.0.3.5) lib/action_view/rendering.rb:116:in `_render_template'
actionpack (6.0.3.5) lib/action_controller/metal/streaming.rb:218:in `_render_template'
actionview (6.0.3.5) lib/action_view/rendering.rb:103:in `render_to_body'
actionpack (6.0.3.5) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
actionpack (6.0.3.5) lib/action_controller/metal/renderers.rb:142:in `render_to_body'
actionpack (6.0.3.5) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (6.0.3.5) lib/action_controller/metal/rendering.rb:36:in `render'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
activesupport (6.0.3.5) lib/active_support/core_ext/benchmark.rb:14:in `block in ms'
/Users/renevanpelt/.rvm/rubies/ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
activesupport (6.0.3.5) lib/active_support/core_ext/benchmark.rb:14:in `ms'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (6.0.3.5) lib/active_record/railties/controller_runtime.rb:34:in `cleanup_view_runtime'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:43:in `render'
wicked_pdf (2.1.0) lib/wicked_pdf/pdf_helper.rb:46:in `call'
wicked_pdf (2.1.0) lib/wicked_pdf/pdf_helper.rb:46:in `render_with_wicked_pdf'
wicked_pdf (2.1.0) lib/wicked_pdf/pdf_helper.rb:30:in `render'
actionpack (6.0.3.5) lib/action_controller/metal/implicit_render.rb:35:in `default_render'
actionpack (6.0.3.5) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.0.3.5) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.0.3.5) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.3.5) lib/abstract_controller/base.rb:195:in `process_action'
actionpack (6.0.3.5) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (6.0.3.5) lib/abstract_controller/callbacks.rb:42:in `block in process_action'
activesupport (6.0.3.5) lib/active_support/callbacks.rb:112:in `block in run_callbacks'
activesupport (6.0.3.5) lib/active_support/core_ext/time/zones.rb:66:in `use_zone'
app/controllers/dashboard_controller.rb:32:in `set_time_zone'
activesupport (6.0.3.5) lib/active_support/callbacks.rb:121:in `block in run_callbacks'
activesupport (6.0.3.5) lib/active_support/callbacks.rb:139:in `run_callbacks'
actionpack (6.0.3.5) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.5) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.5) lib/active_support/notifications.rb:180:in `block in instrument'
activesupport (6.0.3.5) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (6.0.3.5) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.5) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (6.0.3.5) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
activerecord (6.0.3.5) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (6.0.3.5) lib/abstract_controller/base.rb:136:in `process'

更新:我生成了一个新的 rails 6 应用程序,它运行良好。给出错误的应用程序只是从 rails 5 迁移到 rails 6。也许这就是这两种情况之间的区别所在。

4

1 回答 1

3

今天刚遇到同样的问题。原来我使用的是 ruby​​ 2.5,但then在 ruby​​ 2.6 中引入。

将 ruby​​ 升级到 2.6.6 解决了这个问题。

于 2021-04-04T05:22:04.063 回答