Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 Assets Precompilation with multiple manifest files

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

like image 436
l33z3r Avatar asked Apr 23 '13 11:04

l33z3r


People also ask

How are rails assets served to the server?

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.

What is the default location for the rails manifest file?

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).

Where are the assets in the rails asset pipeline?

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.

How do remote clients know when to refetch assets in rails?

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 .


1 Answers

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

like image 151
Zoltan Avatar answered Oct 25 '22 21:10

Zoltan