I'm developing a project that consists in both a chrome extension and a spa. And, here is my problem: I have a lot of javascript that is common to both parts, what I'd like to do is:
example.com/chrome-extension/application.js
). Ideally this response (2) would have both data (from ruby) and the regular result of an asset pipeline.
File: app/views/chrome-extension/application.js.erb
Global.data = { somekey: '<%= @some_value %>' } # append, inline, the same results that I'd get from `application.js` or, even better, from a second asset pipeline `chrome-extension.js`"
Any thoughts? :D
Found it :)
Rails.application.assets.find_asset('application.js').to_s
is what I was looking for.
FYI I created two different files
application.js
//= require rails-ujs
//= require turbolinks
//= require_tree lib <- Magic here
//= require_tree spa
//= require index
lib.js
(common to spa and chrome-extension)
//= require_tree ./models
//= require_tree ./resources
//= require_tree ./whatever
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.