how to change rails to development mode - ruby-on-rails

In the documentation of rails (3.2.3) it says
In development mode (which is what you’re working in by default), Rails reloads your application with every browser request, so there’s no need to stop and restart the web server.
But clearly my app loads in production mode out of the box.(I can type Rails.env and see it).
Why?
I then go to environment.rb and add
ENV["RAILS_ENV"] = "development"
and still it is in production.
Any idea?
Edit : Here you go
#Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
MyAppName::Application.initialize!
ENV["RAILS_ENV"] = "development"

Possible solution for your situation could be:
rails server -e development

Though this is not a solution try to start the Rails server this way:
RAILS_ENV=development bundle exec rails s
What do you see if put <%= Rails.env %> somewhere in you layout file?

If you are using Phusion Passenger, then add the following to your virtual host configuration file:
RailsEnv development
In other words, on my system, you would vim /etc/apache2/sites-available/[name of app] so that it looks like the following:
<VirtualHost *>
ServerName example.com
DocumentRoot /home/yourname/htdocs/example.com/public
RailsEnv development
</VirtualHost>
You would then need to restart the web server:
sudo /etc/init.d/apache2 reload
Credit goes to: http://my.opera.com/williamn/blog/2009/03/03/how-to-make-phusion-passenger-run-in-development-mode

Related

How do I change the rails environment an app I just deployed to production?

I just deployed a dummy rails 3.1.0.rc6 app to a rackspace server. Two things
First when i ssh in the run
rails c
Sprockets::Environment#static_root is deprecated
Loading development environment (Rails 3.1.0.rc6)
irb(main):001:0> Rails.env
=> "development"
Does this mean its in development environment and if so how do i change to production and second in the log folder i have
ls log
development.log passenger.3000.log production.log
but they are all blank for some reason
here is my url and it appears that something is wrong but no logs indicate the problem
<VirtualHost 50.57.119.54:80>
ServerAdmin test#tes.com
ServerName active.posnation.net
# ServerAlias
DocumentRoot /var/www/active.posnation.net/public
ErrorLog /var/www/active.posnation.net/logs/error.log
RailsEnv production
<Directory "/var/www/active.posnation.net/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When you run rails c, it will default to development mode. This does not mean your actual live app is running in development mode. If you're using Passenger, it will default to run your app in production mode unless you tell it otherwise.
To get the console to run in development mode, call rails c development instead.
As far as the log files are concerned, have you checked the permissions on the files to make sure Passenger can write to them (and to make sure you can then read them)?

How do I set RAILS_ENV to 'Production' on a DreamHost shared server?

I have a shared server running passenger to server my Rails app. For some reason my RAILS_ENV variable seems to be stuck as 'Development'. How do I set it to 'Production'? Thanks
In a shared hosting environment, you will want to do this in a .htaccess file, placed inside public/. Mine looks like this:
PassengerEnabled on
PassengerAppRoot /home/myuser/myapp/current
RailsEnv production

how to easily run a sinatra/padrino application on rails hoster

is there an easy way to run a sinatra (in particular a padrino) application "as a" rails app?
i guess, there should be some way to translate "rails server" to "padrino start" or something...
(the hoster i'm referring too hosts rails with mod_rails.)
If you're using mod_rails (ie. Passenger), you shouldn't have a problem at all - Passenger can host any rack-based app, and I use it for hosting Sinatra, Padrino and Rails apps on my server. A very basic rackup file is all you need for Sinatra, something like:
require 'sinatra_app'
set :run, false
set :environment, ENV['RACK_ENV'] || 'production'
run Sinatra::Application
The basic config.ru file you'll need for a padrino app is even simpler:
require ::File.dirname(__FILE__) + '/config/boot.rb'
run Padrino.application
There's more you can do, like for handling logging, but that should be all you need to get going. Your Apache vhost config for both Sinatra and Padrino apps is also simple, and very similar to what you'd use for Rails, eg.:
<VirtualHost *:80>
ServerName my.app.com
DocumentRoot "/var/www/apps/myapp/current/public"
RackEnv production
</VirtualHost>
That should be all you need to start - the only major difference is that you use RackEnv instead of RailsEnv.
You should run Sinatra as a Rack
http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_sinatra

Change a Rails application to production

How can I change my Rails application to run in production mode? Is there a config file, environment.rb for example, to do that?
This would now be
rails server -e production
Or, more compact
rails s -e production
It works for rails 3+ projects.
How to setup and run a Rails 4 app in Production mode (step-by-step) using Apache and Phusion Passenger:
Normally you would be able to enter your Rails project, rails s, and get a development version of your app at http://something.com:3000. Production mode is a little trickier to configure.
I've been messing around with this for a while, so I figured I'd write this up for the newbies (such as myself). There are a few little tweaks which are spread throughout the internet and figured this might be easier.
Refer to this guide for core setup of the server (CentOS 6, but it should apply to nearly all Linux flavors): https://www.digitalocean.com/community/tutorials/how-to-setup-a-rails-4-app-with-apache-and-passenger-on-centos-6
Make absolute certain that after Passenger is set up you've edited the /etc/httpd/conf/httpd.conf file to reflect your directory structure. You want to point DocumentRoot to your Rails project /public folder Anywhere in the httpd.conf file that has this sort of dir: /var/www/html/your_application/public needs to be updated or everything will get very frustrating. I cannot stress this enough.
Reboot the server (or Apache at the very least - service httpd restart )
Enter your Rails project folder /var/www/html/your_application and start the migration with rake db:migrate. Make certain that a database table exists, even if you plan on adding tables later (this is also part of step 1).
RAILS_ENV=production rake secret - this will create a secret_key that you can add to config/secrets.yml . You can copy/paste this into config/secrets.yml for the sake of getting things running, although I'd recommend you don't do this. Personally, I do this step to make sure everything else is working, then change it back and source it later.
RAILS_ENV=production rake db:migrate
RAILS_ENV=production rake assets:precompile if you are serving static assets. This will push js, css, image files into the /public folder.
RAILS_ENV=production rails s
At this point your app should be available at http://something.com/whatever instead of :3000. If not, passenger-memory-stats and see if there an entry like 908 469.7 MB 90.9 MB Passenger RackApp: /var/www/html/projectname
I've probably missed something heinous, but this has worked for me in the past.
If you're running on Passenger, then the default is to run in production, in your apache conf:
<VirtualHost *:80>
ServerName application_name.rails.local
DocumentRoot "/Users/rails/application_name/public"
RailsEnv production ## This is the default
</VirtualHost>
If you're just running a local server with mongrel or webrick, you can do:
./script/server -e production
or in bash:
RAILS_ENV=production ./script/server
actually overriding the RAILS_ENV constant in the enviornment.rb should probably be your last resort, as it's probably not going to stay set (see another answer I gave on that)
If mipadi's suggestion doesn't work, add this to config/environment.rb
# force Rails into production mode when
# you don't control web/app server and can't set it the proper way
ENV['RAILS_ENV'] ||= 'production'
Change the environment variable RAILS_ENV to production.
$> export RAILS_ENV=production
You can also pass the environment to script/server:
$ script/server -e production
rails s -e production
This will run the server with RAILS_ENV = 'production'.
Apart from this you have to set the assets path in production.rb
config.serve_static_assets = true
Without this your assets will not be loaded.
RAILS_ENV=production rails s
OR
rails s -e production
By default environment is developement.
As others have posted: rails server -e production
Or, my personal fave: RAILS_ENV=production rails s
In Rails 3
Adding Rails.env = ActiveSupport::StringInquirer.new('production') into the application.rb and rails s will work same as rails server -e production
module BlacklistAdmin
class Application < Rails::Application
config.encoding = "utf-8"
Rails.env = ActiveSupport::StringInquirer.new('production')
config.filter_parameters += [:password]
end
end
It is not a good way to run rails server in production environment by "rails server -e production", because then rails runs as a single-threaded application, and can only respond to one HTTP request at a time.
The best article about production environment for rails is Production Environments - Rails 3
for default server : rails s -e production
for costum server port : rails s -p [port] -e production, eg. rails s -p 3002 -e production
By default server runs on development environment: $ rails s
If you're running on production environment: $ rails s -e production or $ RAILS_ENV=production rails s
Please make sure you have done below in your environment.rb file.
ENV['RAILS_ENV'] ||= 'production'
If you application runs in shared hosting environment or phushion passenger, you might need to need make changes in .httaccess (inside public folder) and set mode as production.

How to disable caching in Rails?

How can I disable caching for my rails site?
I'm running Passenger (mod_rails) and my site is running in 'development' mode:
'ENV['RAILS_ENV'] ||= 'development'
Any help?
By default Passenger will set RAILS_ENV to 'production'. The line ENV['RAILS_ENV'] ||= 'development' will only cause the Rails environment to be set to 'development' if it has not already set.
You need to add RailsEnv development to your virtual host configuration for the site to make Passenger run Rails in the development environment.
Okay, so I'll answer this question in case anybody else runs into the same problem. Basically, mod_rails was ignoring my 'development' setting that I had set in the environment.rb file. Adding this to my virtualhost configuration for my site fixed it, however:
RailsEnv "development"
See this link for more details.
Hope that helps somebody else!

Resources