2016-08-04 12 views
0

Hallo Ich habe Probleme, meine CSS zu laden, in meiner grundlegenden Schienen App. Ich tat rails g controller static_pages Das gab mir eine static_pages.scss, die von der Asset-Pipeline standardmäßig geladen werden sollte, richtig? Ich habe require_tree. in meiner application.css Datei:Warum wird mein CSS in meiner Rails-App nicht geladen?

/* 
* 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 

*/ 

Hier ist meine static_pages.scss Datei:

// 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; 
} 

Und wenn ich die static_pages # Homepage anzeigen der Hintergrund ist weiß, so dass der CSS nicht geladen wird.

Und hier ist mein 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> 

Ich habe keine Änderungen an der Konfiguration der Applikation. Danke für die Hilfe.

+0

haben Sie Ihren Webserver neu gestartet? – davideghz

+0

Ja, ich habe es mehrmals neu gestartet – srlrs20020

+0

Ich habe gegoogled und gefunden: 'RAILS_ENV = Entwicklung Rake Assets: clean' - führen Sie es in Ihrem Terminal. Dies sollte Ihre generierten CSS-Dateien löschen und erzwingt Rails, um die CSS-Ausgabe von Ihren Sass- oder SCSS-Dateien zu regenerieren. – davideghz

Antwort

1

Versuchen Sie diesen Weg wie unten, da ich den roten Hintergrund bekomme;

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 
*/ 

Hoffe, es hilft !!!

+1

Was haben Sie gegenüber der ursprünglichen Frage geändert? – davideghz

Verwandte Themen