`<module:Rails>':类服务器的超类不匹配(TypeError) [英] `<module:Rails>': superclass mismatch for class Server (TypeError)
问题描述
我已经看到了这个和其他几个问题,但他们的问题和我的不太一样.
I have seen this and several others question, but their problems are not similar to mine.
我已将以下代码添加到 config/boot.rb
中,以在端口 8081 上运行我的服务器
I have added the following code to the config/boot.rb
, to run my server on port 8081
module Rails
class Server
def default_options
super.merge({Port: 8081})
end
end
end
然后我尝试运行 rails s
,我遇到了这个错误:
Then I tried to run rails s
, and i face with this erorr:
/usr/local/rvm/gems/ruby-2.2.1/gems/railties-4.2.4/lib/rails/commands/server.rb:7:in `<module:Rails>': 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 `<top (required)>'
推荐答案
做你想做的事的更好方式:
A better way to do what you want:
require 'rails/commands/server'
module DefaultOptions
def default_options
super.merge!(Port: 8081)
end
end
Rails::Server.prepend(DefaultOptions)
错误消息的原因是因为您试图重新定义 Rails::Server
类并更改它的继承结构.Rails::Server
继承自 ::Rack::Server
,但是您的代码试图说它不再如此.因此,您会收到超类不匹配错误.
The reason for the error message is because you are attempting to redefine the Rails::Server
class and changing it's inheritance structure. Rails::Server
inherits from ::Rack::Server
, however your code is trying to say it no longer does. Therefore, you get your superclass mismatch error.
这篇关于`<module:Rails>':类服务器的超类不匹配(TypeError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!