0
質問は、このプルリクエストを指し:それはまだマージされていないのでhttps://github.com/rails/rails/pull/23211のRails:パッチActionCable(新しいアダプタを追加)
、私は自分のアプリケーションには、このパッチを当てる猿にしたいです。
私は、今lib/core_extenstions/subsctiption_adapter/test.rb
にこのサブスクリプション・アダプタを入れて初期化monkey_patch.rb
に私が試してみてください。
#require 'lib/action_cable/test.rb'
#autoload ActionCable::SubscriptionAdapter::Test
module ActionCable
module SubscriptionAdapter
puts Rails.root.join('lib/core_extensions/action_cable/test.rb').inspect
autoload :Test, Rails.root.join('lib/core_extensions/action_cable/test.rb')
puts Test.inspect
end
end
その後:
MacBook-Pro-Vaceslav:mvp_c slava$ bundle exec rails c test
Running via Spring preloader in process 93788
Loading test environment (Rails 5.0.2)
irb: warn: can't alias context from irb_context.
irb(main):001:0> server = ActionCable.server
=> #<ActionCable::Server::Base:0x007f890e812628 @mutex=#<Monitor:0x007f890e812600 @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f890e8125b0>>, @pubsub=nil, @worker_pool=nil, @event_loop=nil, @remote_connections=nil>
irb(main):002:0> server.pubsub
LoadError: Could not load 'action_cable/subscription_adapter/test'. Make sure that the adapter in config/cable.yml is valid. If you use an adapter other than 'postgresql' or 'redis' add the necessary adapter gem to the Gemfile.
だから、問題の原因はここにある:
https://github.com/rails/rails/blob/master/actioncable/lib/action_cable/server/configuration.rb
def pubsub_adapter
adapter = (cable.fetch("adapter") { "redis" })
path_to_adapter = "action_cable/subscription_adapter/#{adapter}"
begin
require path_to_adapter
rescue Gem::LoadError => e
raise Gem::LoadError, "Specified '#{adapter}' for Action Cable pubsub adapter, but the gem is not loaded. Add `gem '#{e.name}'` to your Gemfile (and ensure its version is at the minimum required by Action Cable)."
rescue LoadError => e
raise LoadError, "Could not load '#{path_to_adapter}'. Make sure that the adapter in config/cable.yml is valid. If you use an adapter other than 'postgresql' or 'redis' add the necessary adapter gem to the Gemfile.", e.backtrace
end
adapter = adapter.camelize
adapter = "PostgreSQL" if adapter == "Postgresql"
"ActionCable::SubscriptionAdapter::#{adapter}".constantize
end
これを回避する方法がわかりません。