【问题标题】:require_tree argument must be a directoryrequire_tree 参数必须是目录
【发布时间】:2015-04-09 11:18:25
【问题描述】:

我想拥有一个包含不同 css、javascript 和图像文件的 onepager,用作我的应用程序的登录页面。

我将我的 css 移到了名为 onepager 的子文件夹下的 vendor/assets 文件夹中。我使用了一个子文件夹,因为我只会将这些文件用于 onepager 而不会用于其他任何东西。

例如

vendor/assets/stylesheets/onepager/

我创建了一个单独的布局,它引用了单独的 css 文件。 > onepager.html.erb

<%= stylesheet_link_tag    'onepager', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'onepager', 'data-turbolinks-track' => true %

在文件 onepager.js 和 onepager.css.scss 中,我希望它们引用 vendor/assets/xxx/onepager/ 文件夹中的文件。我添加了以下代码,但出现错误。

onepager.css.scss

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree ./onepager/
*/

onepager.js

/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree ./onepager/
*/

我得到了要求树不是目录的错误?这很奇怪,因为它是一个目录,我假设供应商资产中的文件是自动加载的?

我该如何解决这个问题?

require_tree 参数必须是目录 (在/home/ubuntu/workspace/app/assets/stylesheets/onepager.css.scss:13)

【问题讨论】:

  • 你用ruby-on-railsruby-on-rails-3ruby-on-rails-4标记了这个。你用的是哪个版本。请修正您的标签。

标签: ruby-on-rails asset-pipeline


【解决方案1】:

自己找到了答案。

我必须补充:

//= require_tree ../../../vendor/assets/javascripts/onepager

css 文件也是如此。之后,错误页面通知我用它提供的代码更新 config/initializers/assets.rb 文件。

我现在工作。

来源: https://github.com/rails/rails/issues/1223

【讨论】:

  • 很高兴您找到了解决方案!再次查看您的代码后,它似乎很清楚。没有做足够的研究,删除我的问题。顺便说一句,你不喜欢将代码放在资产目录中的 onepager 中,因为它的 your 代码?
  • AFAICS、Rails 文档以及 assets_path 表明应该可以访问 vendor/assets 中的内容,就像它们在 app/assets 中一样。但我也需要这个相对路径。有谁知道文档是否错误,或者我们的配置是否错误或......(Rails 5.0.1)。
猜你喜欢
  • 2011-12-31
  • 2017-06-06
  • 2017-07-28
  • 2017-01-10
  • 2015-10-07
  • 2015-08-07
  • 1970-01-01
  • 2022-10-21
  • 2017-06-24
相关资源
最近更新 更多