4

I have seen this and several others question, but their problems are not similar to mine.

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

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)>'
Community
  • 1
  • 1
Sal-laS
  • 11,016
  • 25
  • 99
  • 169

3 Answers3

15

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)

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.

smoak
  • 14,554
  • 6
  • 33
  • 33
5

For Rails 5.1 the following line in config/boot.rb will do the trick:

ENV['PORT'] = '8081'

Link to the source.

Alexander Azarov
  • 12,971
  • 2
  • 50
  • 54
2

In Rails 5.2

in config/puma.rb I added this code.

#port        ENV.fetch("PORT") { 3000 }
bind        'tcp://0.0.0.0:3001'

And it works!

mahfuz
  • 2,728
  • 20
  • 18