【问题标题】:application.css / application.js doesn't work on rails 3.1application.css / application.js 不适用于 rails 3.1
【发布时间】:2014-01-19 11:29:48
【问题描述】:

我开始学习 Rails 3.1。但是,css 不起作用。

app/assets/stylesheets/里面有一些scss,但是没有出现在application.css中

我创建 productshoge.css(不是 scss),但它也不起作用。

我认为“这将自动包含此目录中可用的所有样式表”,但不包含任何 css。

当我尝试重新制作新应用程序(rails new XXX)时,我遇到了同样的情况。

有人能给我建议吗?

文件夹
应用程序/资产/样式表/
├── application.css
├── carts.css.scss
├── layout.css.scss
├── line_items.css.scss
├── products.css.scss
├── productshoge.css
├──scaffolds.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 . 
*/



环境
发展

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1


    【解决方案1】:

    只需将 Gemfile 中的 rails 版本更新为 3.2.13 并运行 bundle update。您还应该从 application.css 中删除 *= require productshoge.css

    希望对你有所帮助。

    【讨论】:

    • 感谢您的回答我将rails更新到3.2.12,问题解决了。资产管道工程。非常感谢
    【解决方案2】:

    请确保您已将该行包含在/app/views/layouts/application.html.erb

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

    【讨论】:

    • 谢谢你的回答,但我在添加时遇到了同样的情况:media => "all"  X(
    【解决方案3】:

    您必须手动添加 CSS,例如,

    应用程序/资产/样式表/

    * require carts
    * require layout
    * require line_items
    * require products
    * require productshoge
    * require scaffolds
    * require store
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 2013-09-15
      • 2014-12-03
      • 2021-04-27
      • 2012-02-16
      • 2013-02-01
      • 1970-01-01
      相关资源
      最近更新 更多