Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku always runs assets:precompile with the production environment for Rails 3.2

I have my Heroku environment set to staging but my assets are always compiled in the production environment.

Here's heroku config:

GEM_PATH            => vendor/bundle/ruby/1.9.1
LANG                => en_US.UTF-8
PATH                => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV            => staging

I've added an exception to the production.rb file so I know which env it's running when compiling the assets. The server starts up just fine running heroku run console shows that I'm running staging.

It's just when running assets:precompile that it's always in production.

I'd be happy to post any other config file if required.

I can add that I'm running Rails 3.2.2 and the Cedar stack on heroku


Output from heroku run rake about:

About your application's environment
Ruby version             1.9.2 (x86_64-linux)
RubyGems version         1.3.7
Rack version             1.4
Rails version            3.2.2
JavaScript Runtime       therubyracer (V8)
Action Pack version      3.2.2
Active Support version   3.2.2
Middleware               Rack::Cache, ActionDispatch::Static, Rack::Lock, #, Rack::Runtime, Rack::Auth::Basic, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Callbacks, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, ActionDispatch::ParamsParser, ActionDispatch::Head, Rack::ConditionalGet, Rack::ETag, ActionDispatch::BestStandardsSupport
Application root         /app
Environment              staging

And running heroku run rake assets:precompile gives:

/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets

Should I just give up and email Heroku?

like image 972
Nicklas A. Avatar asked Mar 22 '12 20:03

Nicklas A.


People also ask

How do I Precompile assets in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What is asset Precompile in Rails?

You should use app/assets for files that must undergo some pre-processing before they are served. In production, Rails precompiles these files to public/assets by default. The precompiled copies are then served as static assets by the web server. The files in app/assets are never served directly in production.

What does bundle exec rake assets Precompile do?

4.1 Precompiling Assets. Rails comes bundled with a rake task to compile the asset manifests and other files in the pipeline to the disk. Compiled assets are written to the location specified in config.


2 Answers

Apparently I needed to enable a plugin to make it work.

like image 53
Nicklas A. Avatar answered Sep 17 '22 18:09

Nicklas A.


Try setting RAILS_ENV to staging as well and see if that makes Heroku any happier.

like image 40
Veraticus Avatar answered Sep 19 '22 18:09

Veraticus