0

我正在嘗試將最初在rails 3.0中完成的項目升級到rails 3.1,我想啓用資產管道。作爲rails 3.0項目,它使用public/文件夾來存儲cssjs和圖像文件。我發現的一些看法有stylesheet_link_tag:所有與資產管道

<%= stylesheet_link_tag :all %> 
在他們

,並沒有資產的管道,這將導致在public/stylesheets納入所有css文件。

這裏有沒有和這個使用資產管道的東西相當的話,包括所有的東西在app/assets/stylesheets?或只是所有的asset/stylesheets目錄?或者如果有更多rails3.1方式來做到這一點,我也完全開放。我只是想找到升級這個項目的正確方法。

回答

1

默認情況下,資產管道包括app/assets/stylesheets中的樣式。從導向:http://guides.rubyonrails.org/asset_pipeline.html

與3.1版本開始,Rails的默認連接所有 JavaScript文件到一個主.js文件和所有的CSS文件合併成一個 主.css文件。正如您將在本指南後面介紹的那樣,您可以通過 自定義此策略,以您喜歡的任何方式對文件進行分組。在 製作中,Rails將MD5指紋插入每個文件名,以便該文件由Web瀏覽器緩存。你可以通過改變這個指紋,只要您更改文件內容自動發生 無效 緩存..

在你/app/assets/stylesheets目錄,你應該有一個文件名爲application.css(注意純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 top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
*= require_self 
*= require_tree . 
*/ 

還要注意,應該被全部註釋掉這樣的,它是如何Rails的讀取它。

+0

所以我應該在視圖中包含''application''然後呢? –

+1

您的'/ app/views/layout/application.html.erb'文件應該包含在標題中: <%= stylesheet_link_tag「application」,:media =>「all」%> –