我开始研究Rails 3.1。但是,css不起作用。
app / assets / stylesheets /中有一些scss,但它们没有出现在application.css中
我创建了productshoge.css(不是scss),但它也不起作用。
我认为“这将自动包含此目录中可用的所有样式表”,但不包含任何css。
当我尝试重新制作新应用程序(rails new XXX)时,我遇到了同样的情况。
有人会建议我吗? 文件夹
应用程序/资产/样式表/
├──application.css
├──carts.css.scss
├──glan.css.scss
├──line_items.css.scss
├──products.css.scss
├──productshoge.css
├──脚手架.css.scss
└──store.css.scss
的 assets.path
irb(main):001:0> y Rails.application.config.assets.paths
---
- /Users/sekai/study/depot/app/assets/images
- /Users/sekai/study/depot/app/assets/javascripts
- /Users/sekai/study/depot/app/assets/stylesheets
- /Users/sekai/study/depot/vendor/assets/stylesheets
- /Library/Ruby/Gems/2.0.0/gems/jquery-rails-3.0.4/vendor/assets/javascripts
的 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_self
*= require productshoge.css
*= require_tree .
*/
的输出(view-source:http://localhost:3000/?debug_assets=1
)
<html>
<head>
<title>Pragprog Booksオンラインストア</title>
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" /><!-- <label id="code.slt"/> -->
<script src="/assets/application.js?body=1" type="text/javascript"></script><!-- <label id="code.jlt"/> -->
<meta content="authenticity_token" name="csrf-param" />
<meta content="asIA91Z9Dm0OnAPa4ki6LlWcUst/GypczrubeGSDegM=" name="csrf-token" /><!-- <label id="code.csrf"/> -->
</head>
输出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_self
*= require productshoge.css
*= require_tree .
*/
的环境
发展
答案 0 :(得分:0)
请确保您已在/app/views/layouts/application.html.erb
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application" %>
答案 1 :(得分:0)
只需将Gemfile中的rails版本更新为3.2.13并运行bundle update。您还应该从application.css
中删除* = require productshoge.css我希望这会对你有所帮助。
答案 2 :(得分:0)
您必须手动包含CSS,例如
应用程序/资产/样式表/
* require carts
* require layout
* require line_items
* require products
* require productshoge
* require scaffolds
* require store