2016-08-04 114 views
0

嗨我无法让我的CSS加载在我的基本导轨应用程序。我做了rails g controller static_pages 这给了我一个static_pages.scss应该由资产管道默认加载权?我有require_tree。在我application.css文件:为什么我的rails应用程序中的基本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 any plugin's vendor/assets/stylesheets directory 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 bottom of the 
* compiled file so the styles you add here take precedence over styles defined in any styles 
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new 
* file per style scope. 
* 
*= require_tree . 
*= require_self 

*/ 

这里是我的static_pages.scss文件:

// Place all the styles related to the static_pages controller here. 
// They will automatically be included in application.css. 
// You can use Sass (SCSS) here: http://sass-lang.com/ 

body { 
    background-color: red; 
} 

当我查看static_pages#主页的背景是白色的,所以CSS没有加载。

这里是我的application.html.erb:

<!DOCTYPE html> 
<html> 
<head> 
    <title>t</title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    <%= csrf_meta_tags %> 

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> 

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> 

</head> 
<body class="container-fluid"> 

    <%= yield %> 

</body> 
</html> 

我还没有更改任何配置应用程序。谢谢您的帮助。

+0

你有没有重新启动你的网络服务器? – davideghz

+0

是的,我已经多次重新启动它 – srlrs20020

+0

我搜索了一下,发现这个:'RAILS_ENV =开发耙资产:干净' - 在你的终端中运行它。这应该删除您生成的CSS文件并强制导轨从Sass或SCSS文件重新生成CSS输出。 – davideghz

回答

1

尝试这种方式,因为我得到红色背景;

static_pages_controller.rb

class StaticPagesController < ApplicationController 
end 

的routes.rb

Rails.application.routes.draw do 

    root 'static_pages#home' 

end 

home.html.erb

screenshot.png

static_pages.scss

// Place all the styles related to the static_pages controller here. 
// They will automatically be included in application.css. 
// You can use Sass (SCSS) here: http://sass-lang.com/ 
body { 
    background-color: red; 
} 

application.html.erb

<!DOCTYPE html> 
<html> 
<head> 
    <title>Apple</title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

<%= yield %> 

</body> 
</html> 

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 any plugin's vendor/assets/stylesheets directory 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 bottom of the 
* compiled file so the styles you add here take precedence over styles defined in any styles 
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new 
* file per style scope. 
* 
*= require_tree . 
*= require_self 
*/ 

希望它可以帮助!

+1

你对原始问题做了什么改变? – davideghz