Ruby on rails:资产中的样式表并不起作用

时间:2014-05-08 19:27:39

标签: css ruby-on-rails asset-pipeline assets

即使在阅读http://guides.rubyonrails.org/asset_pipeline.html之后,我仍然遇到资产管道问题。我仍然遇到麻烦。

当我在开发中加载页面时,我的css没有呈现,看起来css没有被考虑在内,因为如果我把这个css放入我页面标题中的<script></script> home .html.erb 它完美无缺。

我在 app / assets / stylesheets / bootstrap.css.scss

中有这个样式表

bootstrap.css.scss

/* BOOSTRAP CSS */
/* /BOOSTRAP CSS */

.form-group {
  width: 250px;
  font-size: 10px;
  opacity: 1;
 } 


.panel {
    width:300px;
    margin-left: auto;
    margin-right: auto;
    opacity: 0.8;
    z-index: 10000;

}

.btn-default {
    border: 1px solid #28c3ab;
    color: #1abc9c;
    background-color: #f1c40f;
}




.jumbotron {
    background-color:#ecf0f1;
    color:#1abc9c;
} 

.btn-default {
    color: #1abc9c;
    background-color: #f1c40f;
}

.btn-default:hover,
.btn-default:focus {
    border: 1px solid #28c3ab;
    outline: 0;
    color: #1abc9c;
    background-color: #3498db;
}


.btn-primary {
    border: 1px solid #28c3ab;
    color: #f1c40f;
    background-color: #1abc9c;
}

.btn-primary:hover,
.btn-default:focus {
    border: 1px solid #28c3ab;
    outline: 0;
    color: #f1c40f;
    background-color: #3498db;
}

这是app / assets / stylesheets / application.css中的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 'masonry/transitions'
 *= require_tree
 *= require font-awesome 
 *= require bootstrap
 *= require magnific-popup
 */

我不确定出了什么问题,我试图预先编译资产,仍然无法正常工作,我还能错过什么?

我的布局中有我的样式表链接, app / views / layouts / application.html.erb

    <%= stylesheet_link_tag "application", media: "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>

2 个答案:

答案 0 :(得分:0)

预编译资产以进行生产时,请确保您的开发环境也不使用这些资产。所以检查你的html并确保你可以看到每个css文件而不仅仅是application.css

如果您确实发现自己正在使用预编译资产,请运行rake assets:clean,然后您的开发环境将使用正确的css文件。

答案 1 :(得分:0)

我的样式表没有加载,我遇到了类似的问题。但这种情况正在发生,因为我有所改变 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>

代码行

<%= stylesheet_link_tag 'default', media: 'all', 'data-turbolinks-track': 'reload' %>

在构建我的应用程序的早期阶段的application.html.erb文件中......但我将其更改回

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>已加载样式表。

application.html.erb位于rails应用程序目录的view / layout /文件夹中。