在我发布此消息后,我想到了一个好主意。这是给遇到这个问题的其他人的。
删除全部要求。所以从 application.js 中删除这一行
//= require_tree .
并从 application.css 中删除这一行
*= require_tree .
在您的 application.html.erb 中更改为如下所示
<%= stylesheet_link_tag "application", params[:controller], :media => "all" %>
<%= javascript_include_tag "application", params[:controller] %>
将此添加到您的 config/initializers/assets.rb
%w( controller_one controller_two controller_three ).each do |controller|
Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}.css"]
end
**用你的控制器名称替换控制器一、二等。
现在是最酷的部分。将子文件夹添加到样式表作为您的控制器名称。在示例中,我的是“家”。将您的 css 文件添加到其中。获取您的 home.css(在您的主样式表文件夹中)并为其提供以下代码:
/*
* 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 home/freelancer
*= require home/bootstrap
*= require home/font-awesome
*/
将“freelancer”替换为您的文件名。我在样式表/主文件夹中的文件名是 freelancer.css
我相信有一种方法可以要求子文件夹中的所有内容,但我并不肯定。喜欢
*= require home/.
但不是正面的。