Rails 5 problems with multiple manifest files

1.1k views Asked by At

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:

  1. 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.

  2. 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);
    
  3. 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
1

There are 1 answers

0
Fabrizio Bertoglio On BEST ANSWER

Solutions Tested

  1. 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
  2. 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
  3. 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.