未初始化的常量 > ActionCable::Server::Configuration::ApplicationCable
Posted
技术标签:
【中文标题】未初始化的常量 > ActionCable::Server::Configuration::ApplicationCable【英文标题】:uninitialized constant > ActionCable::Server::Configuration::ApplicationCable 【发布时间】:2016-03-27 13:07:18 【问题描述】:当我运行服务器时,它的抛出错误显示在下面的日志中。我用谷歌搜索了很多,但没有找到背后的原因。有人请给它一些亮光。
宝石文件
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta1', '< 5.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
gem 'active_model_serializers', '~> 0.10.0.rc1'
group :development, :test do
gem 'byebug'
end
gem 'puma'
group :development do
gem 'spring'
end
日志:
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/configuration.rb:15:in
`initialize': uninitialized constant
ActionCable::Server::Configuration::ApplicationCable (NameError) from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `new' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `block in <class:Base>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:72:in
`block in mattr_reader' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:55:in
`each' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:55:in
`mattr_reader' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/activesupport-5.0.0.beta1/lib/active_support/core_ext/module/attribute_accessors.rb:208:in
`mattr_accessor' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:16:in `<class:Base>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:12:in `<module:Server>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:7:in
`<module:ActionCable>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/server/base.rb:6:in
`<top (required)>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable.rb:43:in
`server' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/actioncable-5.0.0.beta1/lib/action_cable/process/logging.rb:10:in
`<top (required)>' from /home/pd/Documents/EventsApp/config.ru:7:in
`block in <main>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in
`instance_eval' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/builder.rb:55:in
`initialize' from /home/pd/Documents/EventsApp/config.ru:in `new'
from /home/pd/Documents/EventsApp/config.ru:in `<main>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in
`eval' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/builder.rb:49:in
`new_from_string' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/builder.rb:40:in
`parse_file' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/server.rb:318:in
`build_app_and_options_from_config' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/server.rb:218:in
`app' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:56:in
`app' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/rack-2.0.0.alpha/lib/rack/server.rb:353:in
`wrapped_app' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:134:in
`log_to_stdout' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/server.rb:74:in
`start' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:90:in
`block in server' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:85:in
`tap' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:85:in
`server' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands/commands_tasks.rb:49:in
`run_command!' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/command.rb:20:in
`run' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/railties-5.0.0.beta1/lib/rails/commands.rb:19:in
`<top (required)>' from /home/pd/Documents/EventsApp/bin/rails:9:in
`require' from /home/pd/Documents/EventsApp/bin/rails:9:in `<top
(required)>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/client/rails.rb:28:in
`load' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/client/rails.rb:28:in
`call' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/client/command.rb:7:in
`call' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/client.rb:28:in
`run' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/bin/spring:51:in `<top
(required)>' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/binstub.rb:11:in
`load' from
/home/pd/.rvm/gems/ruby-2.2.4/gems/spring-1.6.0/lib/spring/binstub.rb:11:in
`<top (required)>' from /home/pd/Documents/EventsApp/bin/spring:13:in
`require' from /home/pd/Documents/EventsApp/bin/spring:13:in `<top
(required)>' from bin/rails:3:in `load' from bin/rails:3:in `<main>'
【问题讨论】:
我在尝试使用路由 'mount ActionCable.server => '/cable'' 挂载它时遇到了这个问题 @MacTeo 看看我下面的回答,应该能解决你的问题。 【参考方案1】:该错误与您的项目中没有正确的 ActionCable 文件有关。你需要像这样的app/channels/application_cable/channel.rb
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
和app/channels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
【讨论】:
这也解决了我的问题。我将 4.x.x 项目升级到 5.x.x 以使用动作电缆,这是在遵循新 5.x.x 项目的早期教程时缺少的项目之一。【参考方案2】:如果您从以前的版本升级(当 actioncable 不在捆绑包中时),请检查 config/application.rb
是否包含
require "action_cable/engine"
【讨论】:
【参考方案3】:我在尝试将 ActionCable 与 Rails 4.2.5 一起使用时遇到了同样的问题,解决方案是将以下内容添加到 config/application.rb:
config.autoload_paths += %W(#config.root/app/channels)
这是 ActionCable gem:
gem 'actioncable', github: 'rails/actioncable', branch: 'archive'
【讨论】:
【参考方案4】:根据昨天的DHH's video tutorial,Spring
和 ActionCable
依赖之间存在问题,因此在 Rails 5 的最终版本之前,您需要使用 --skip-spring
选项重新创建您的项目。
【讨论】:
感谢您的回复,但这不起作用。同样的错误。 只是一个健全的检查:你是否在从 Gemfile 中删除bundle
后运行它? :-)
从 gemfile 中删除 Spring 不起作用,但是在新的 rails 应用程序中 --skip-spring
之后它工作正常。
这不是正确的答案,因为 spring 与这个问题无关。错误是由于缺少ApplicationCable
模块而引发的。弹簧问题是与赛璐珞不可重新加载有关的完全不同的问题(因此不适用于弹簧)。 --skip-spring
接缝处理空白项目的原因是 b/c 我在下面建议的文件已经存在。 -1
@PardeepDhingra 看看我下面的回答,应该可以解决你的问题。【参考方案5】:
我还通过添加以下内容来解决 Heroku 部署的问题:
require "action_cable/engine"
在config/application.rb
【讨论】:
以上是关于未初始化的常量 > ActionCable::Server::Configuration::ApplicationCable的主要内容,如果未能解决你的问题,请参考以下文章
Rails:为啥“has_many ...,:通过=> ...”关联导致“NameError:未初始化的常量...”