0

Rails 4.2.1, Ruby 2.2.6, sprockets 3.7.1, sprockets-rails 3.2.0

I am trying to deploy to my staging server with a new .js file and the precompile did nothing. Here is the output with '--trace'.

  ** Invoke assets:precompile (first_time)
  ** Invoke assets:environment (first_time)
  ** Execute assets:environment
  ** Invoke environment (first_time)
  ** Execute environment
  ** Execute assets:precompile
  ** Invoke ckeditor:nondigest (first_time)
  ** Invoke environment 
  ** Execute ckeditor:nondigest

I have tried running rake assets:clean, assets:clobber, and assets:precompile with and without 'RAILS_ENV=staging bundle exec' prepended to those commands - nothing. I deleted the assets folder and ran the precompile again - nothing. I have incremented the assets.version - nothing.

I tried putting my assets precompile directive in /config/initializers/assets.rb, /config/environments/staging.rb, and /config/application.rb

 Rails.application.config.assets.version = '1.0.2'
 Rails.application.config.assets.precompile += %w(
  admin.css
  admin.js
  new_file.js
 )

Is there a way to tell what file the assets:precompile is looking in?

* UPDATE *

Setting assets.compile = true and deploying makes the assets precompile. I was under the impression that this directive would make rails serve assets on the fly instead of using the precompiled assets. Is this correct to do?

 Rails.application.config.assets.compile = true
Peter Black
  • 1,142
  • 1
  • 11
  • 29

1 Answers1

1

Yes setting config.assets.compile = true will kill your apps performance and lead to long page loads randomly in production. Try running "bundle exec rake assets:precompile RAILS_ENV=production" so it uses your production environment config. file. As to your other question about where it's looking for precompiling, there is a prefix setting in the rails config. you can use to state where you want precompiled assets to go. Ex. config.assets.prefix = '/production' But the default is to your public assets folder.

Update: ( I was going to write a long post on the subject but it looks like the creator of it wrote why to avoid in great detail already and can be found at this link:

config.assets.compile=true in Rails production, why not?

Community
  • 1
  • 1
bkunzi01
  • 4,504
  • 1
  • 18
  • 25
  • The assets.prefix defines where the assets go but how do you figure out which file is actually read when compiling assets? To the best of my knowledge it should read the initializers/assets.rb OR environments/staging.rb. I was able to precompile all of my assets after setting assets.compile = true.Then I deleted the assets folder again and tried your suggestion of running the precompile for production and again, nothing. Until I figure out a proper solution I may just push twice for assets updates. Once for precompiling assets and another time to set assets.compile back to false. – Peter Black Feb 27 '17 at 13:56
  • I guess I am also a little confused about how assets.compile = true is bad. If you set that value to true and it precompiles everything in your application won't it serve the precompiled assets anyway? Doesn't that directive only apply when there is no precompiled asset? In that case wouldn't it be better to set it true? Instead of your asset not being delivered to the end-user and throwing an error, the user would just wait a couple of extra seconds and the page would load properly. Am I wrong in my assumptions? – Peter Black Feb 27 '17 at 14:24
  • I'll update my answer as to why you don't want assets.compile set to true because it's a somewhat long explanation. You are correct in that Rails will look at your initializer/assets.rb file for which assets to precompile when running rake assets:precompile. Check my update for response on live compilation of assets. – bkunzi01 Feb 27 '17 at 22:34
  • Ok. Good to know. So why do my assets only compile when that is set to true? – Peter Black Feb 28 '17 at 03:53
  • Are you running "bundle exec rake assets:precompile RAILS_ENV=production" ? If you're not specifying the environment it will go off of your dev. settings. – bkunzi01 Mar 01 '17 at 04:02
  • I have tried staging and production with and without bundle exec. – Peter Black Mar 01 '17 at 15:14