views:

37

answers:

3

Once I start coding a rails app, I am by default in development mode.

What should I do to change my rails environment to test or production mode ?

can I work in multiple environments simultaneously ?

+1  A: 

It depends how you are running the application. When you run your tests then they automatically use the test environment. If you are using script/server (e,g, using WEBrick, Mongrel etc.) then you can pass the name of the environment to use on the command line e.g. script/server -e production.

  • If you are using Phusion Passenger then the environment can be specified using the RailsEnv configuration directive

  • If you are using the Rails console then specify the environment name directly: script/console production

  • You can create your own environments too. This Railscast has the details

John Topley
if you want to run both development and production the same time, you must change the port, so that the 2 instances are not trying to use the same one:`script/server -p 3001 RAILS_ENV=production`
Leventix
@Leventix Good point, thanks.
John Topley
suppose if I run a unit test by saying like ruby unit/post-test.rb , will rails automatically know that I want to use test environment... after all we are running just a ruby file by a simple ruby command.. how can rails know about this ?
lakshmanan
A: 

to run application on production mode type in console

ruby script/server -e production

TO RUN SAME APPLICATION ON DIFFERENT ENVIORMENT you have to use different ports

like

ruby script/server -e production -p 3001

AND

ruby script/server -p 3002
Salil
if I run my app in production mode, it gives me an error like "table posts not available" .. where as its already there and was working during development mode..
lakshmanan
Check your database.yml . The production environment probably uses a different database then the development mode . "rake db:create RAILS_ENV =production" and then "rake db:migrate RAILS_ENV=production" should set up the db for production as well .
NM
Those ports are the same!
John Topley
@john:- oooohhhh i edit it.that should be different. Thanx john
Salil
A: 

script/server -e production for production mode

more in script/server --help

ohho