问题
thanks for your help.
My Problem
In my Rails 5 application I have 2 layouts, for this reason I need to set up multiple manifest files.
What I have done
I did the following:
- The two
layouts
have auser.html.erb
and amain.html.erb
html file, there I linked with the correct tags myapplication.js
inuser.html.erb
and mymain.js
formain.html.erb
. The file loads, if I follow
localhost:3000/assets/application.js
the full content of the js files included in the manifest is displayed, while at/assets/main.js
are displayed only the following lines:(function() { }).call(this);
I Followed the instructions included in the following discussion Rails 4 Assets Precompilation with multiple manifest files, but they did not work
config.assets.precompile += %w( main.js )
I searched Stackoverflow and I read the documention, but no answer to this problem has ever been found. I am using:
* rails (5.0.1)
* sprockets (3.7.1)
* sprockets-rails (3.2.0)
Update
In main.js file I included the following as test:
//= require jquery
//= require bootstrap-sprockets
//= require jquery.easing
Thanks a lot for your help, I really hope that you can help me. Best Regards Fabrizio Bertoglio
回答1:
Solutions Tested
- I tried to add in my assets.rb the digest file as by this instructions, but this did not solve the problem asset pre compilation for subdirectory manifest file
- I have Rails 5 and Ruby 2.3.3p222. Some old Stackoverflow discussion suggest that the problem is caused from Ruby 2.0 and they suggest to revert to Ruby 1.9 Javascript files are not included from manifest
- The best solution (that i read in a Stackoverflow discussion), was to edit the html div and classes so that the different JS files of the different layouts could all be included in one manifest file, without triggering console errors in the browser.
My Solution
My temporary solution was, as I had 2 layouts and one of the js file would cause console errors in the other layout, as they would both use the same ids or classes, would be commenting JS code that I would not need (as I am using a HTML-Layout with many effects that I do not use) and not including the entire file causing problems (custom.js) in my manifest file.
I would include this file separately in my layout main.html.erb
file with the tags.
<%= javascript_include_tag 'custom', 'data-turbolinks-track': 'reload' %>
This would solve all the problems.
来源:https://stackoverflow.com/questions/42305538/rails-5-problems-with-multiple-manifest-files