3

what's the differences between these two tasks, why i need to add RAILS_ENV=production when cap deploy?

thanks!

3 Answers 3

7

You need to specify RAILS_ENV=production environment variable so that your config/environments/production.rb configuration file is used when precompiling assets. It usually contains production configuration for assets pipeline:

config.assets.js_compressor = :uglifier
config.assets.digest = true

If you omit RAILS_ENV=production then development configuration will be used (config/environments/development.rb).

3
  • so basicly run RAILS_ENV=production rake assets:precompile on local or productions, the files generated in public/assets should be the same ? can i sync them when deploy?
    – dfang
    Commented Jun 4, 2014 at 5:06
  • They may vary insignificantly based on what JavaScript runtime is installed locally and on server. Look here to get a better idea how to do local assets pre-compilation. Commented Jun 4, 2014 at 5:10
  • @Andrey Chernih Rails guides are missing stuff like this.
    – ahnbizcad
    Commented Sep 4, 2014 at 14:25
1

The first one will precompile your assets on your local dev box (development environment) and the other will precompile your assets on your production environment. Your settings in your config files are most likely different and so it will go of what is configured off what is in the environment config for whatever you set RAILS_ENV to.

0

Was going to write as a comment but too long...

--

Production vs Local

Something you also need to consider with this, is if you're precompiling for the production environment, it essentially compiles & configures your files for that environment

Simply, this means if you have any special conditions / dependencies for production only, using RAILS_ENV=production will use these over your local setup. This is why you'll have this setup in your Gemfile:

#Gemfile
group :production do
   gem 'xxxx'
end

--

SHELL VARIABLES

Something else you need to appreciate is RAILS_ENV is a SHELL VARIABLE. This means that whenever you run a shell session (I.E load cmd), these variables can be set to provide specific functionality.

In relation to RAILS_ENV, it means you'll be able to tell Rails to run in production mode for the time being; as opposed to running in development, testing or staging modes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.