Asset overload on Rails engines: a file with additional gem resources is required to fail

I am trying to create a Rails engine for "administration". Suppose Engine has the following assets:

ENGINE/app/assets β”œβ”€β”€ javascripts β”‚  └── railsyard β”‚  β”œβ”€β”€ admin.js.coffee β”‚  β”œβ”€β”€ admin_customizations.js.coffee ... 

Where admin.js.coffee requires admin_customizations.js.coffee , that is, an empty file ready to overwrite the Rails hosting application.

 [ENGINE/app/assets/javascripts/my_engine/admin.js.coffee] #= require admin_customizations # ...some code... [ENGINE/app/assets/javascripts/my_engine/admin_customizations.js.coffee] # Override this empty file to add custom JS behaviour! 

Everything works wonderfully until I try to claim some assets coming from a recycled gem:

 [APP/app/assets/javascripts/my_engine/admin_customizations.js.coffee] #= require modernizr # this line gets ignored alert "Foobar" # this line works 

The modernizr-rails gem is the dependency of the hosting, not the engine. Note that if I try to require modernizr from an asset file that is not an override of any engine asset file, everything will work again.

Is there any way to fix this?

+6
source share
1 answer

I believe that I did what you described without having the problem you are talking about.

Are you sure something else is not happening there? The necessary line, which is ignored, does not make much sense - the stars should include either the required file or raise it if it cannot find it. Just silently doing nothing seems right.

Perhaps you are causing an error in stargazers or using a pipeline to use rail resources - but most likely something is happening there.

Are you sure that you did not accidentally provide your own empty modernizr.js file in the local application and / or engine, accidentally overriding the one you want modernizr to self-service?

Lines

sprockets require must be in the comments that precede any code in the file, they must be in the original comment block. can it get you?

or maybe something else that is actually not what you think.

I really don't use coffeescript myself, is there something strange with coffeescript in some way?

0
source

Source: https://habr.com/ru/post/912988/


All Articles