2

谢谢你的帮助。

我的问题

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

我做了什么

我做了以下事情:

  1. 这两个layouts有一个user.html.erb和一个main.html.erbhtml 文件,在那里我用正确的标签 my application.jsinuser.html.erb和 my main.jsfor链接main.html.erb
  2. 文件加载,如果我按照localhost:3000/assets/application.js清单中包含的 js 文件的全部内容显示,而 at/assets/main.js仅显示以下几行:

    (function() {
    }).call(this);
    
  3. 我按照以下讨论中包含的说明使用多个清单文件进行 Rails 4 资产预编译,但它们不起作用

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

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

* rails (5.0.1)
* sprockets (3.7.1)
* sprockets-rails (3.2.0)

更新

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

//= require jquery
//= require bootstrap-sprockets
//= require jquery.easing

非常感谢您的帮助,我真的希望您能帮助我。最好的问候法布里齐奥·贝托利奥

4

1 回答 1

-1

测试的解决方案

  1. 我尝试按照此说明在我的 assets.rb 中添加摘要文件,但这并没有解决问题 资产预编译子目录清单文件
  2. 我有 Rails 5 和 Ruby 2.3.3p222。一些旧的 Stackoverflow 讨论表明问题是由 Ruby 2.0 引起的,他们建议恢复到 Ruby 1.9 清单中不包含 Javascript 文件
  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.

于 2017-02-19T09:46:18.040 回答