Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 4: use different server port depending on environment
    primarykey
    data
    text
    <p>I'm trying to automate the configuration of my rails application and I want to be able to start the app without specifying the port, as I would like it to be chosen depending on the environment.</p> <p>Specifically (something simple to start with) to run the application on port 3000 if environment is production, on port 3500 otherwise.</p> <p>So, following this answer, I've added the following to my boot.rb file:</p> <pre><code>require 'rails/commands/server' module DefaultOptions def default_options super.merge!(Port: Rails.env.production? ? 3000 : 3500) end end Rails::Server.send(:prepend, DefaultOptions) </code></pre> <p>Unfortunately I'm doing something wrong, because this is the output when I run <code>rails s</code>:</p> <pre><code>/home/luca/projects/ads_manager/config/boot.rb:10:in `default_options': undefined method `env' for Rails:Module (NoMethodError) from /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:287:in `parse_options' from /usr/local/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:184:in `options' from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:58:in `set_environment' from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:42:in `initialize' from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `new' from /usr/local/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `&lt;top (required)&gt;' from bin/rails:4:in `require' from bin/rails:4:in `&lt;main&gt;' </code></pre> <p>Any idea why Rails.env is not available? </p> <p>Alternatives to obtain the same result are more than welcome indeed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload