1

I am building my blog and its admin section is significantly different from the rest of the site. So I decided to have separate manifests as per what I understand in the The Asset Pipeline documentation.

Problem:

The admin section works as expected with the styles applied properly. But in production it doesn't. I have run rake assets:precompile and it only generates one version which is application-[blah].js. and not a admin_lite-[blah].js

What could I be doing wrong? Help is greatly appreciated.

More information

  • app/assets/stylesheets/admin_lite.css
  • <%= stylesheet_link_tag "admin_lte", media: 'all' %> \
  • app/assets/javascripts/admin_lite.js
  • <%= javascript_include_tag "admin_lte" %>
  • Added initilizer (config/intilizers/assets.rb) Rails.application.config.assets.precompile += ['admin_lite.js', 'admin_lite.css']
  • ran `RAILS_ENV bin/rake assets:precompile
  • Only generates some thing like applicaiton-[signature].js && application-[signature].css
  • The css and js links in the admin section is as /stylesheets/admin_lite.css /javascripts/admin_lite.css ( not the format it is for application-* varients which have a signature ).

The css output

<link href="/stylesheets/admin_lte.css" media="all" rel="stylesheet" />
<script src="/javascripts/admin_lte.js"></script>

Updates

  • added config.assets.precompile += ['admin_lite.js', 'admin_lite.css'] to config/environments/production.rb (and also development.rb to test)
  • added config.assets.precompile += ['admin_lite.js', 'admin_lite.css'] to application.rb

with no success

Fix / Resolved

The error was a typo, where I had used the wrong file name and thus it was not compiled. So, if you...

  • run rake assets:precompile
  • application.css compiles but not your custom manifest (ex: admin.css)
  • Check the spelling
  • I really wish it to have raised an exception.
Ziyan Junaideen
  • 3,270
  • 7
  • 46
  • 71
  • You want to add `Rails.application.config.assets.precompile += ['admin_lite.js', 'admin_lite.css']` to `config/environments/production.rb` this is what rails will call in precompiling. – j-dexx Jul 07 '14 at 16:48
  • Does make sense, let me try. I was following the link I posted about asset pipeline, it says to have an internalize named assets.rb (need to update question). – Ziyan Junaideen Jul 07 '14 at 17:07
  • No it didn't work. I added it to development as well and ran precompile, only has application- varients. – Ziyan Junaideen Jul 07 '14 at 17:25
  • 1
    If an asset is missed, rails can fall back. In your production.rb is the line 'config.assets.compile = true' – nil Jul 07 '14 at 17:32
  • Also, I don't know how you're deploying; but just to make sure, are you restarting the rails app in production? – nil Jul 07 '14 at 17:37
  • 1
    Is it _lite or _lte? Your code seems to be using both – Frederick Cheung Jul 07 '14 at 17:42
  • @FrederickCheung - You are my guardian angel. It worked when I change `little` to `lte`. Do add it as an answer and I will accept it. Thanks a lot – Ziyan Junaideen Jul 07 '14 at 20:23
  • @RussellKompinski Does `config.assets.compile = true` act as a fallback? Meaning which if the assets are not compiled, it will use run time compile it? Thanks for the info – Ziyan Junaideen Jul 07 '14 at 20:24
  • Yea it does, but after researching I learned that it's best not to, and here's why: http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not - So it looks like I will stop doing that! – nil Jul 07 '14 at 22:31

2 Answers2

1

It looks like the name of the manifest you are asking it to precompile doesn't match the setting - try changing lite to lte

Frederick Cheung
  • 83,189
  • 8
  • 152
  • 174
1

I've found (with Rails 4.1.6, at least), that the file extension used in the config.assets.precompile and the javascript_include_tag are of vital importance.

I recently added the following to my production.rb:

  config.assets.precompile += %w(google/infobox.js)

And in the HAML file that would use the asset I had:

=javascript_include_tag "google/infobox"

Of course, this works like a charm in development mode!

So, I promote the code to production and when I ran rake assets:precompile on the server I see the precompiled file get created:

Writing public/assets/google/infobox-85c3151833c8f22f374f4fb25b7f917f.js

Awesome!

But alas no...

Long story short, I had to explicitly add the ".js" extension into javascript_include_tag to be:

=javascript_include_tag "google/infobox.js"

Hope this saves somebody some time in the future.

Also hope that somebody isn't me stumbling upon my own answer the next time it happens to me and I can't remember why it happened.

Darren Hicks
  • 4,946
  • 1
  • 32
  • 35