2

At the moment, I am unable to run my server because apparently I seem to be in the wrong environment.

Suppose I am in the test environment, how do I switch to the production environment? Because right now, every time I am trying to run my app they keep telling me the server is running on the production environment.When I check to see if its running it still says that no application is running....

Is there a command I can use to switch environments?

Tito
  • 109
  • 5
  • 13
  • You can always run another mode by calling the `-e` on the server command. `rails s -e production` Is this the answer you are looking for? – Kevin Etore Jan 02 '17 at 12:39
  • You don't really ever start the rails server in the test environment. Its almost always done by the test framework (minitest or RSpec) when running integration tests. You usually run the server in the development environment on your local machine and in production on the production server. You can either use the -e option as suggested by @KevinEtore or set the `RAILS_ENV` ENV var in your shell http://guides.rubyonrails.org/configuring.html#rails-environment-settings – max Jan 02 '17 at 12:42
  • 1
    You cannot switch environments once Rails has been loaded in a process (for server, console, tests, rake tasks,...). You need to specify the environment when launching the process, and cannot change it afterwards. Stop the process, and start again with another environment if you need it. – Eric Duminil Jan 02 '17 at 13:09

2 Answers2

4

I think you should try

rails server -e production
rails s -e production

This command will work from rails3 or later

Mansi Shah
  • 517
  • 5
  • 15
  • note `rails` will load the first rails installation it can find whereas `bin/rails` loads the rails version specific to the project https://stackoverflow.com/questions/25334160/what-is-the-difference-between-rails-vs-bin-rails – Aiden Cullo Jul 26 '23 at 14:25
2

Set the RAILS_ENV to production

RAILS_ENV=production rails s
Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88