Ruby on rails RubyonRails css资产管道组织问题
我只能在我的应用程序的show.html.haml页面上使用特定的表格样式。具体来说,我不希望将此样式应用于_form.html.haml partials中的表单。以下是样式元素:Ruby on rails RubyonRails css资产管道组织问题,ruby-on-rails,css,asset-pipeline,Ruby On Rails,Css,Asset Pipeline,我只能在我的应用程序的show.html.haml页面上使用特定的表格样式。具体来说,我不希望将此样式应用于_form.html.haml partials中的表单。以下是样式元素: table { border-collapse: collapse; width:100%; } td, th { border: 1px solid gray; padding:5px; text-overflow: ellipsis; white-s
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的小文件,并将其包含在my application.js中,如下所示:
*=需要web应用主题/数据表
问题是:它不仅会影响show.html.haml页面中的表(我想要),还会影响_form_html.haml部分(我不想要)。显然,关于资产组织,有一些东西我并不完全了解。以下是app/assets/stylesheets目录中my 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影响的表,并相应地进行更改 或者,您可以从清单中删除此文件,并从带有
样式表\u link\u标记的视图中调用它,如下所示:
<%=stylesheet_link_tag "web-app-theme/data_tables"%>
但是,您不希望将其用于小文件,因为它会增加对服务器的请求量。谢谢。我按照您的建议创建了一个特定的类(以及相关的元素)。这个效果最好。