gpt4 book ai didi

ruby-on-rails - Rails 不使用生成的 CSS 文件

转载 作者:太空宇宙 更新时间:2023-11-03 18:28:05 25 4
gpt4 key购买 nike

我有一个 Rails 3.1 应用程序。我生成一个 Controller ,只是为了展示发生了什么:

$ rails generate controller Rocks index show edit
create app/controllers/rocks_controller.rb
route get "rocks/edit"
route get "rocks/show"
route get "rocks/index"
invoke haml
create app/views/rocks
create app/views/rocks/index.html.haml
create app/views/rocks/show.html.haml
create app/views/rocks/edit.html.haml
invoke rspec
create spec/controllers/rocks_controller_spec.rb
create spec/views/rocks
create spec/views/rocks/index.html.haml_spec.rb
create spec/views/rocks/show.html.haml_spec.rb
create spec/views/rocks/edit.html.haml_spec.rb
invoke helper
create app/helpers/rocks_helper.rb
invoke rspec
create spec/helpers/rocks_helper_spec.rb
invoke assets
invoke coffee
create app/assets/javascripts/rocks.js.coffee
invoke scss
create app/assets/stylesheets/rocks.css.scss

太棒了。看起来不错。生成的 app/assets/stylesheets/rocks.css.scss。正是我想要的。

现在,导航到 http://localhost:3000/rocks/index,我检查源代码并查看:

  <head> 
...
<link href="/assets/application.css?body=1" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/rocks.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
...
</head>

rocks.css 不见了,我不知道为什么。有没有人遇到过这样的事情?

最佳答案

你的 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_tree .
*/

最重要的:

*= require_tree . 

然后 rocks.css 应该包含在 application.css 中,这是使用 assets

的优势

关于ruby-on-rails - Rails 不使用生成的 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8001169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com