3

Ruby Version: 2.0.0

Rails Version: 4.0.1

This is a follow-up to my previous question: Why do assets fail to load in production mode?. This was mostly fixed by setting config.serve_static_assets = true in production.rb.

However, now I still have one stylesheet and one javascript file that aren't being pulled in. which (coincidentally) should be pulling in it's own set of dependencies.

In my application.html.erb file I have:

<%= stylesheet_link_tag "application", media: "all"  %>
<%= stylesheet_link_tag "frontend", media: "all" %>

However, that seems to be parsing to two very different things. Here is the output:

<link href="/assets/application-1c1eb49916824f465443a709172a580a.css" media="all" rel="stylesheet">
<link href="/stylesheets/frontend.css" media="all" rel="stylesheet">

And in case it makes a difference, here is what frontend.css actually looks like:

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the top of the
 * compiled file, but it's generally better to create a new file per style scope.
 *
 *= require_self
 *= require_tree ./frontend
 *= require front_end
 */

What am I missing?

Community
  • 1
  • 1
drewwyatt
  • 5,989
  • 15
  • 60
  • 106

1 Answers1

4

In config/application.rb, add frontend.css to config.assets.precompile:

# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
config.assets.precompile += %w( frontend.css )

Don't forget to do this if you create other CSS and JavaScript manifest files.

Chris Peters
  • 17,918
  • 6
  • 49
  • 65
  • Nailed it. Thank you. – drewwyatt Apr 17 '14 at 04:11
  • You're welcome. I remember going through all of this when deploying my first production app. Good luck. :) – Chris Peters Apr 17 '14 at 19:02
  • Ok. I added the assets' entries in `config.assets.precompile` in `config/application.rb` just as sugested. i.e using `config.assets.precompile += %w( whateverasset|css|js )` This worked – mwangi Aug 12 '16 at 20:12
  • 2
    It should be noted that the location of this configuration has moved to `config/initializers/assets.rb` in newer versions of Rails. – Chris Peters Aug 12 '16 at 20:31