|
|
In development your app's assets (images, stylesheets, javascripts) all load
|
|
|
fine, but in production in your shared app some or all of the assets have broken
|
|
|
links.
|
|
|
|
|
|
For example, say you have an app with these four files that are not included in
|
|
|
the application.css or application.js manifests:
|
|
|
|
|
|
* structures.js.coffee
|
|
|
* structures.css.scss
|
|
|
* simulations.js.coffee
|
|
|
* simulations.css.scss
|
|
|
|
|
|
When you run the app, application.css and application.js load, but the links to
|
|
|
the other stylesheets and javascripts are broken. Why?
|
|
|
|
|
|
In production, the only javascripts and stylesheets you can link to are the ones
|
|
|
sprockets creates - which are the manifest files or ones specified in the
|
|
|
precompile array.
|
|
|
|
|
|
* application.js and application.css are in these arrays by default
|
|
|
* structures.js/css and simulations.js/css, however, are not
|
|
|
|
|
|
To precompile add these you'll need to add these to the precompile arrays. This
|
|
|
is mentioned in this section:
|
|
|
|
|
|
* http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
|
|
|
|
|
|
You would add a file config/initializers/assets.rb and inside that file you
|
|
|
would add them to the precompile array:
|
|
|
|
|
|
Rails.application.config.assets.precompile += ['structures.js',
|
|
|
'simulations.js', 'structures.css', 'simulations.css']
|
|
|
|
|
|
Notice the manifest for the stylesheets are 'structures.css', 'simulations.css'
|
|
|
even though the actual files are 'structures.css.scss', 'simulations.css.scss'.
|
|
|
|
|
|
|
|
|
**Note that this is not a recommended approach to managing assets!**
|
|
|
|
|
|
Rather, if you want to namespace a set of styles for partciular pages, you wrap
|
|
|
those styles with a class prefix and include the styles in the manifest.
|
|
|
|