Rails How to Switch Between Dev and Production Mode

Rails how to switch between dev and production mode?

If you are using Rails 4.2 then you must know rails uses "spring" to make it faster. So in that case you can use following commands:

For Development just run

Rails 4.2
bin\rails s
Otherwise
rails s

For Production just run

Rails 4.2
bin\rails s -e production
Otherwise
rails s -e production

To setup production database
if database in production does not exist then run

Rails 4.2
bin/rake db:create db:migrate RAILS_ENV=production
Otherwise
rake db:create db:migrate RAILS_ENV=production
bundle exec rake db:create db:migrate RAILS_ENV=production

If DB already exists the:

Rails 4.2
bin/rake db:migrate RAILS_ENV=production
Otherwise
rake db:migrate RAILS_ENV=production
OR
bundle exec rake db:migrate RAILS_ENV=production

Also if you want to stop spring or start spring then use following commands:

 bin/spring stop
bin/spring start

how to change rails to development mode

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?

Change a Rails application to production

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.

  1. 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

  2. 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.

  3. Reboot the server (or Apache at the very least - service httpd restart )

  4. 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).

  5. 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.

  6. RAILS_ENV=production rake db:migrate

  7. RAILS_ENV=production rake assets:precompile if you are serving static assets. This will push js, css, image files into the /public folder.

  8. 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.

Rails - switch environment to production automatically

Easy:

rails server RAILS_ENV=production

Or:

rails s -e production

Or you meant without this extra thing? If that so, it depends on which server you use. You can install Puma for example, and add config file, in which you can specify the default environment.

This question could help in case of set rails env for ngnx or passenger.

Rails application going into production mode when it's supposed to be in staging mode

You need to tell passenger which rails environment to use. It's defaulting to production.

<VirtualHost *:80>
ServerName myserver.com

DocumentRoot /home/myappstaging/public

PassengerRuby /path-to-ruby

<Directory /home/myappstaging/public>
Allow from all
Options -MultiViews
Require all granted
RailsEnv staging
</Directory>
</VirtualHost>

rails - how to run in production mode against the development database?

Have you changed the production node in your database.yml to use mysql2 adapter?

production:
adapter: mysql2
database: your_database
host: 127.0.0.1
username:
password:

Switching from development to production in rails 3.2.6

config.assets.initialize_on_precompile = false

^ That line in your application.rb is to tell the precompile function to precompile lazily. This means that it will precompile assets only in your main application. If you set this to true, it will be able to pre-compile assets included in other referenced Gems. So unless you have the jquery files explicitly in your application's assets folder, it is probably getting missed on pre-compilation - thus it is not included in your application.js.

NOTE

This line: config.assets.compile = true should tell your application to fall back to the assets pipeline if a pre-compiled asset is missed - ideally this would mean that it would find the jquery asset from the normal pipeline.

However my guess is that since technically it does find application.js, your application is not aware that there has been a missed asset, so it loads the pre-compiled application.js and then there is just no way it can get the jquery code.

Solution

Sorry for long-winded explanation, but please try the following - Set the following line in your config/application.rb

config.assets.initialize_on_precompile

to be true

And then you'll of course have to rebuild and redeploy :) Let me know if this helps!!



Related Topics



Leave a reply



Submit