简体   繁体   中英

How to extend Rails Mountable Engine Assets in Application?

Imagine we have Rails Engine blog .

The engine's structure is:

blog
    assets
    javascripts
        blog
            master.js
            application.js
    controllers
        ...
    helpers
        ...

application.js is

//= require_tree .

master.js holds some JavaScript code.

Also I have my application using this engine at /blog .

My question is: How can I add some JavaScript code to engine from my application?

Solution is:

  1. Ensure bundle files (application.js, application.css) on plugin and application have different names. In my example plugin's bundle will be bundle.js, and application's bundle — application.js
  2. bundle.js will look like:

    require_tree .

  3. application.js will look like:

    require blog/bundle

    require_tree .

The problem was in name overlapping - application's bundle was overlapping engines one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM