How do I force rake assets:precompile to generate

2019-08-06 10:18发布

问题:

I'm using RefineryCMS and in the admin section I need to include a JS file. To do that you have to set a config value

config.register_javascript "bootstrap.modal"

http://antonivanopoulos.com/refinerycms-admin_restyle-a-gem-to-make-refinery-cms-a-little-prettier/

It works in development. When I precompile the assets for production, RefineryCMS admin pages give a 404 error because bootstrap.modal-7bc4667810e04a7a7ccf02099c81a882.js doesn't exist in public/assets. Instead it's embedded in application.js which Refinery admin doesn't use.

Refinery will insert a separate JS tag for that file:

<script src="/assets/bootstrap.modal-b7d8ffab93a0b4c1ed4d9681ec6647f4.js" type="text/javascript"></script>

The file exists as an app asset, but doesn't get fingerprinted as its own file.

$ ls app/assets/javascripts/bootstrap.modal.js
app/assets/javascripts/bootstrap.modal.js
$ rake assets:precompile
...
$ ls public/assets/boot*
ls: cannot access public/assets/boot*: No such file or directory

I can't just include application.js because there is a lot more stuff that messes up the display of the admin pages.

I read the entire asset pipeline guide but found nothing useful.

http://guides.rubyonrails.org/asset_pipeline.html

Rails 3.2.14.

回答1:

I found I can add individual files to the list of assets to compile so I could get those extra files in production.

production.rb:

config.assets.precompile += %w( bootstrap.modal.js bootstrap.modal.css blog_post_form.js ) # This is for Refinery Admin /config/initializers/refinery/core.rb