hi, uncommenting the line ENV['RAILS_ENV'] ||= 'production', in environment.rb makes no difference to my rails app running under webrick, it still runs in development, and i have restarted the server. Does this line only apply to Apache? I dont have RAILS_ENV set, why is it allways running in development? Thanks
on 2007-05-08 12:52
on 2007-05-08 14:39
Changing environment files isn't a good thing to do. If you want to run WEBrick under production mode, then run: ruby script/server -e production If you're actually trying to run a Rails app in production over WEBrick, I can only recommend that you don't. Go pick up Mongrel if you want a quick and easy production deployment environment. WEBrick is meant and built for development / testing only. Jason
on 2007-05-08 15:17
Thanks Jason, but would that line in envirnment.rb effect webrick at all? Heres my problem: Locally i run webrick, on the production environment i dont have access to httpd.conf, and run apache. I use capistrano for deployment. After a deployment i had to go and change environment.rb too be production _ only way to do it without httpd.conf access. I thought i would change it in environment.rb in subversion to be production, so after a capistrano deployment it would work immediatly, but wast sure what affect that would have on webrick locally. I was surprised to find that webrick ignored that line, is that expected behaviour? Thankyou
on 2007-05-08 15:42
Does the apache setup not explicitly set -RAILS_ENV=production? Or maybe I'm just misreading what you've posted. Anyway, I think it's the ||= that's messing with you. ||= means "set equal if nothing exists there yet", so as ENV['RAILS_ENV'] is already set to 'development', that line is ignored. Change it to =, it will force production mode. Jason
on 2007-05-08 16:00
Thanks Jason 1. I dont know, i am not able to view it. 2. Thanks, i was not aware of that, but still behaving unexpectedly: I set ENV['RAILS_ENV'] = 'production' i check my environment variables, "echo $RAILS_ENV" which comes blank. i remove the "production" part of my databse.yml file, and run webrick, and it starts fine in development mode, where else could it be set?
on 2007-05-08 16:40
WEBrick starts up in development mode by default, you have to specify with '-e production' to get into that mode. Also, while Ruby ENV is the system environment, it's only set for the execution of the ruby script and not changed for your shell session, so "echo $RAILS_ENV", as you saw, doesn't give you anything. I guess I still don't understand the problem. Is a production deploy acting like development or are you wanting to test your app in production mode to make sure there are no bugs there? Jason
on 2007-05-08 16:58
Ill try to explain the problem a bit better, i would like to deploy my rails app with a single command using capistrano, and have it work as soon as deployment has completed. Problem is that the only way i can run my application in production mode on my host is by uncommenting the line in environment.rb to set it to production, if its commented out, it seems to run in development. So i have a choice, manually uncomment that line after a deployment, or uncomment that line, and save it to subversion ready for a deployment. My plan was to do the second option, and set RAILS_ENV to development on my local development system to overide the setting in environment.rb. In the process of doing this i discovered that if the line ENV['RAILS_ENV'] ||= 'production', was uncommented in environment.rb, and i had not locally set RAILS_ENV to development, my application would still run as development using webrick. I wanted to understand whether webrick ignored environment.rb and it only had meaning to Apache? or if i had inadvertantly set it to development in some other way - basically i wanted to understand how this was possible. I really appreciate your help Jason, thanks.
on 2007-05-08 17:18
If you look at rails\railties\lib\commands\servers\webrick.rb, you can see where RAILS_ENV set to 'development' on startup. With this set, when Rails loads in environment.rb and sees the line: ENV['RAILS_ENV'] ||= 'production', Ruby says "well RAILS_ENV is already set to 'development', so ignore this line". As for the host, you should get a hold of someone there and find out why apache rails is not configured to run as production. Hope that helps. Jason
on 2007-05-08 18:44
Perfect! i understand now. Thanks Jason for all your help.