In my Rails 5 application I have 2 layouts, for this reason I need to set up multiple manifest files.
I did the following:
The two layouts
have a user.html.erb
and a main.html.erb
html file, there I linked with the correct tags my application.js
in user.html.erb
and my main.js
for main.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)
In main.js file I included the following as test:
//= require jquery
//= require bootstrap-sprockets
//= require jquery.easing
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.