簡體   English   中英

紅寶石在軌道和資產

[英]ruby on rails and assets

我剛剛啟動了我的第一個ruby應用程序。

我將應用程序所需的css和js文件復制到資產文件夾,當我運行該應用程序時,所有css和js都加載到頁面中,我不希望那樣

我的看法很簡單

hello

我的application.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 .
 */

為什么要加載所有資產? 我可以“禁用”此功能嗎?

我要做的就是以特定順序定義視圖文件中所需的文件(css,js),並僅加載特定頁面所需的js。

有特別的評論。 Rails的預處理器會對其進行解釋並插入文件。

 *= require_self
 *= require_tree .

閱讀資產管道 2.4清單文件和指令。

如果您編寫* = require樹,這意味着將添加javascript文件夾上的所有js,並且對css也是如此。 因此刪除這些行。 同時,您可以對應用程序使用資產管理器來管理您的資產(使其在特定頁面上顯示)以進行標准資產管理。我建議您檢查http://railscasts.com/episodes/279-understanding-the -asset-pipeline?view = asciicasthttps://rails-assets.org/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM