2013-03-15 36 views
2

我有一個名爲admin的視圖,並且我想使用僅在此頁面中使用的css文件admin.css。 我在佈局中創建了一個新的佈局admin.html.erb。我在那裏放置什麼,如何編輯application.css,以便admin.css僅在管理視圖中使用,但其他所有樣式表也包含在管理視圖中?In Rails 3如何創建一個包含僅被某個視圖使用的css的佈局

謝謝! 這是我在application.css至今

/* 
* This is a manifest file that'll automatically include all the stylesheets available in this directory 
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at 
* the top of the compiled file, but it's generally better to create a new file per style scope. 
*= require bootstrap_and_overrides 
*= require custom 
*= require admin 
*= require_self 
*/ 

回答

1

不要require adminapplication.css,否則你將結束含有該文件在您的處理CSS文件中的內容。

離開admin.css,因爲它是(該文件將保存所有管理員的CSS資源,你甚至可以引用其他文件,如果你需要的話),從application.css刪除require admin線,並添加您的application.rb如下:

config.assets.precompile += ['admin.css'] 

這將指示資產管道作爲單獨文件預編譯admin.css

然後在你的管理佈局包括:

<%= stylesheet_link_tag "application" %> 
<%= stylesheet_link_tag "admin" %> 

而且在非管理員佈局只包含應用程序。

+0

謝謝,我做了這個,但它沒有奏效。我的管理視圖不包含application.css – user1404536 2013-03-15 05:18:47

相關問題