`’:类Server的超类不匹配(TypeError)
我已经看到了这个和其他几个问题,但他们的问题与我的不相似。
我已将以下代码添加到config/boot.rb
,以便在端口8081上运行我的服务器
module Rails class Server def default_options super.merge({Port: 8081}) end end end
然后我试着运行rails s
,我面对这个erorr:
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/server.rb:7:in `': superclass mismatch for class Server (TypeError) from /usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/server.rb:6:in `'
做你想做的更好的方法:
require 'rails/commands/server' module DefaultOptions def default_options super.merge!(Port: 8081) end end Rails::Server.prepend(DefaultOptions)
出现错误消息的原因是您尝试重新定义Rails::Server
类并更改其inheritance结构。 Rails::Server
inheritance自::Rack::Server
,但是你的代码试图说它不再存在。 因此,您会得到超类错配错误。
对于Rails 5.1 , config/boot.rb
的以下行将config/boot.rb
:
ENV['PORT'] = '8081'
链接到源 。