I have a rails 4 application.
I have 3 sets of manifest files in order to seperate out logic for my app.
These files are
application.js
backoffice.js
pos.js
application.css
backoffice.css
pos.css
In my layout files, I reference these assets using the associated javascript_link_tags
I have added the following to my production.rb file (in order to include these files in the precompilation of assets):
config.assets.precompile += %w( backoffice.js pos.js pos.css backoffice.css )
I then run rake assets:precompile, but it is not picking up the additional files. It only compiles the application.js and application.css manifests.
In production.rb also, I have:
config.serve_static_assets = true
config.assets.compile = false
Anyone any ideas?
thanks
By default Rails assumes assets have been precompiled and will be served as static assets by your web server. During the precompilation phase an SHA256 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disk.
This is used by the Rails helper methods to avoid handing the mapping requests back to Sprockets. A typical manifest file looks like: The default location for the manifest is the root of the location specified in config.assets.prefix ('/assets' by default).
In previous versions of Rails, all assets were located in subdirectories of public such as images, javascripts and stylesheets. With the asset pipeline, the preferred location for these assets is now the app/assets directory. Files in this directory are served by the Sprockets middleware. Assets can still be placed in the public hierarchy.
If there are no digests in the filenames, and far-future headers are set, remote clients will never know to refetch the files when their content changes. Rails comes bundled with a command to compile the asset manifests and other files in the pipeline. Compiled assets are written to the location specified in config.assets.prefix .
If you copy this line
config.assets.precompile += %w( backoffice.js pos.js pos.css backoffice.css )
to config/application.rb
(Rails 4.0) (instead of config/environments/production.rb
) it will work.
I've got a tip from here: Rails 4 assets.precompile
As suggested in the comments, in Rails 4.2 you should write above line in config/initializers/assets.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With