多个清单文件的 Rails 5 问题 [英] Rails 5 problems with multiple manifest files

查看:50
本文介绍了多个清单文件的 Rails 5 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的帮助.

在我的 Rails 5 应用程序中,我有 2 个布局,因此我需要设置多个清单文件.

In my Rails 5 application I have 2 layouts, for this reason I need to set up multiple manifest files.

我做了以下事情:

  1. 这两个 layouts 有一个 user.html.erb 和一个 main.html.erb html 文件,我在那里链接了正确的在 user.html.erb 中标记我的 application.js,在 main.html.erb 中标记我的 main.js.
  2. 文件加载,如果我按照 localhost:3000/assets/application.js 显示清单中包含的 js 文件的完整内容,而在 /assets/main.js 只显示以下几行:

  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);

  • 我遵循了以下讨论中包含的说明Rails4 Assets Precompilation with multiple manifest files,但没用

    config.assets.precompile += %w( main.js )
    

  • 我搜索了 Stackoverflow 并阅读了文档,但从未找到此问题的答案.我正在使用:

    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)
    

    更新

    在 main.js 文件中,我包含以下内容作为测试:

    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. 我尝试按照此说明在我的 assets.rb 中添加摘要文件,但这并没有解决问题子目录清单文件的资产预编译
    2. 我有 Rails 5 和 Ruby 2.3.3p222.一些旧的 Stackoverflow 讨论表明问题是由 Ruby 2.0 引起的,他们建议恢复到 Ruby 1.9 Javascript 文件不包含在清单中
    3. 最佳解决方案(我在 Stackoverflow 讨论中读到的)是编辑 html div 和类,以便不同布局的不同 JS 文件都可以包含在一个清单文件中,不会在浏览器中触发控制台错误.
    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.

    我的解决方案

    我的临时解决方案是,因为我有 2 个布局,其中一个 js 文件会导致另一个布局中的控制台错误,因为它们都使用相同的 id 或类,将 评论 JS 代码 我不需要(因为我正在使用具有许多我不使用的效果的 HTML 布局)并且不在我的清单文件中包含导致问题的整个文件 (custom.js).我会将此文件单独包含在带有标签的布局 main.html.erb 文件中.

    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' %>
    

    这将解决所有问题.

    这篇关于多个清单文件的 Rails 5 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆