`<module:rails>':类Server(TypeError)的超类不匹配

时间:2015-11-22 06:34:53

标签: ruby-on-rails

我见过this和其他几个问题,但他们的问题与我的问题不太相似。

我已将以下代码添加到expect(),以便在端口8081上运行我的服务器

config/boot.rb

然后我尝试运行module Rails class Server def default_options super.merge({Port: 8081}) end end end ,我面对这个错误:

rails s

3 个答案:

答案 0 :(得分:14)

更好的方法来做你想做的事:

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,但您的代码却试图说它不再存在。因此,您会收到超类错误。

答案 1 :(得分:6)

对于Rails 5.1 config/boot.rb中的以下行可以解决问题:

ENV['PORT'] = '8081'

Link to the source

答案 2 :(得分:0)

[HttpPost] public IActionResult Download() { byte[] content = System.IO.File.ReadAllBytes(pathOfTheFile); return File(content, "application/zip", filename); }

Rails 5.2中,我添加了此代码。

config/puma.rb

它有效!