Rails 5 actioncable未定义的方法'fetch'为零:NilClass

问题描述:

我正在使用Rails 5与actioncable,我在获取this error时尝试发送任何抛出的信息actioncable我应该怎么做? 我正试图把这个项目推到Heroku。Rails 5 actioncable未定义的方法'fetch'为零:NilClass

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' 
+0

当'cable.fetch'被调用时,'cable'听起来像'nil'。是这样吗? –

有一个承诺作出这里:enter link description here

通过阅读和更改配置文件用于ActionCable ...

config/redis/cable.yml

config/cable.yml

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

+0

感谢这是工作:D –

+1

有人可以解释为什么会发生这种情况吗?它发生在我身上的还有Rails 5.0.0.beta2 – ftshtw

+0

他们将配置文件更改为对ActionCable后端更模糊,而不是默认Redis。 –