问题 Rails 5 actioncable undefined方法`fetch'代表nil:NilClass


我正在使用Rails 5 actioncable 而我正在接受 这个错误 当尝试发送任何抛出的东西 actioncable 我该怎么办? 我正在尝试将项目推向Heroku。

NoMethodError in MessagesController#create

undefined method `fetch' for nil:NilClass
Extracted source (around line #37):

#35       # Also makes sure proper dependencies are required.
#36       def pubsub_adapter
*37         adapter = (cable.fetch('adapter') { 'redis' })
#38         path_to_adapter = "action_cable/subscription_adapter/#{adapter}"
#39         begin
#40           require path_to_adapter

Extracted source (around line #50):

#48       # Adapter used for all streams/broadcasting.
#49       def pubsub
*50         @pubsub ||= config.pubsub_adapter.new(self)
#51       end
#52 
#53       # All the identifiers applied to the connection class associated with this server.

Extracted source (around line #42):

#40           def broadcast(message)
#41             server.logger.info "[ActionCable] Broadcasting to #{broadcasting}: #{message}"
*42             server.pubsub.broadcast broadcasting, ActiveSupport::JSON.encode(message)
#43           end
#44         end
#45     end


Rails.root: /media/adham/Data/code/rails5test

Application Trace
app/controllers/messages_controller.rb:6:in `create'
app/middleware/chat_action_cable.rb:10:in `call'

5357
2018-01-21 01:36


起源

这听起来像 cable 是 nil 什么时候 cable.fetch 叫做。是这样的吗? - Simon MᶜKenzie


答案:


这里有一个提交: 在此输入链接描述

从...读取并更改ActionCable的配置文件

config/redis/cable.yml

config/cable.yml

......解决了这个问题。此更新旨在允许ActionCable后端不可知。


15
2018-01-21 21:44



谢谢这是工作:D - Adham El-Deeb
有人能解释为什么会这样吗?它也发生在我的Rails 5.0.0.beta2上 - ftshtw
他们将配置文件更改为对ActionCable后端更加模糊,而不是默认为Redis。 - Rob Race