是否有一種方法可以爲單獨導軌控制器提供單獨的css文件夾?我想要結合兩個主題。一個用於我的家庭控制器,當用戶沒有登錄時,另一個用於用戶登錄時的儀表板控制器。這兩個都有多個css和javascript文件。用於單獨導軌控制器的獨立CSS文件夾
我知道如何用一個css文件做到這一點。例如:家庭控制器只讀取home.css。
但我真的很喜歡家庭控制器的文件夾,因爲我想保持組織多個文件。
任何幫助,將不勝感激。
是否有一種方法可以爲單獨導軌控制器提供單獨的css文件夾?我想要結合兩個主題。一個用於我的家庭控制器,當用戶沒有登錄時,另一個用於用戶登錄時的儀表板控制器。這兩個都有多個css和javascript文件。用於單獨導軌控制器的獨立CSS文件夾
我知道如何用一個css文件做到這一點。例如:家庭控制器只讀取home.css。
但我真的很喜歡家庭控制器的文件夾,因爲我想保持組織多個文件。
任何幫助,將不勝感激。
我發佈這個後想到了一個好主意。這是爲了解決這個問題的其他人。
刪除要求全部。所以從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等等。帶着您的控制器名稱。
現在是很酷的部分。將子文件夾添加到樣式表作爲您的控制器名稱。在這個例子中,我的是「家」。添加你的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
*/
替換爲「自由職業者」與以往的文件名是什麼。我的文件名在我的stylesheets/home文件夾中,對於這個文件,是freelancer.css
我相信有一種方法要求所有子文件夾,但我不積極。像
*= require home/.
但不是正面的。