有没有办法让不同的rails控制器有不同的css文件夹?我有两个主题想要结合起来。一个用于我的家庭控制器,当用户未登录时。当用户登录时,一个用于我的仪表板控制器。这两个文件都有多个css和javascript文件。
我知道如何用一个css文件做到这一点。示例:家庭控制器仅读取home.css。
但我真的想要一个文件夹为家庭控制器,因为我想保持有组织的多个文件。
任何帮助都将不胜感激。
发布于 2014-10-08 06:34:04
在我发完这篇文章后,我想出了一个好主意。这是为其他有这个问题的人准备的。
删除全部必填项。因此,从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
**替换controller_one、two等..使用您的控制器名称。
现在是最酷的部分了。在样式表中添加子文件夹作为您的控制器名称。在这个例子中,我的是"home“。将您的css文件添加到其中。获取您的home.css (在您的主stylesheets文件夹中),并为其提供以下代码:
/*
* 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/.
但不是正面的。
https://stackoverflow.com/questions/26243434
复制相似问题