簡體   English   中英

Ruby on Rails CSS資產管道組織問題

[英]Ruby on Rails css assets pipeline organization issue

我只能在應用程序的show.html.haml頁面上使用某種表樣式。 具體來說,我不想將此樣式應用於_form.html.haml局部文檔中的表單。 以下是樣式元素:

  table {
    border-collapse: collapse;
    width:100%;
  }

  td, th {
    border: 1px solid gray;
    padding:5px;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: ellipsis;
  }

  th {
    background-color: #ccc;
    text-shadow: 1px 1px 1px rgba(0,0,0,.2);
  }

我在app / vendor / assets / web-app-theme / stylesheets目錄中創建了一個名為data_tables.css的小文件,並將其包含在我的application.js中,如下所示:

* =需要網絡應用主題/數據表

問題是:它不僅影響show.html.haml頁面中的表(我想要),而且還會影響_form_html.haml部分(我不想要)。 顯然,對於資產組織,我有些不了解。 這是app / assets / stylesheets目錄中我的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 web-app-theme/base
 *= require web-app-theme/style
 *= require web-app-theme/wat_ext
 *= require web-app-theme/data-tables
 *= require formalize
 *= require jquery.ui.core
 *= require jquery.ui.theme
 *= require jquery.ui.tabs
 *= require dataTables/src/demo_table_jui
 *= require_self
 *= require_tree . 
*/

您在清單中聲明的​​所有內容都會在資產編譯期間轉儲到單個文件中。 最好的解決方案是將類分配給您希望CSS影響的表,並相應地對其進行更改。

或者,您可以從清單中刪除此文件,並使用stylesheet_link_tag從視圖中調用它,如下所示:

<%=stylesheet_link_tag "web-app-theme/data_tables"%>

但這不是您想要用於小文件的東西,因為它增加了對服務器的請求量,而沒有增加任何請求。

暫無
暫無

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

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