Question

I start to study Rails 3.1. However, css doesn't work.

There are some scss in app/assets/stylesheets/, but they don't appear in application.css

I create productshoge.css(not scss) but it doesn't work either.

I think "that'll automatically include all the stylesheets available in this directory" , but any css doesn't be included.

when I try to re-make new application ( rails new XXX), I met same situation.

would someone advise me?

folders
app/assets/stylesheets/
├── 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 . 
*/



output(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>

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



environment
development

Was it helpful?

Solution

Just update the rails version in the Gemfile to 3.2.13 and run bundle update. Also you should remove *= require productshoge.css from application.css

I hope this will help you.

OTHER TIPS

Please be sure that you have included that line in /app/views/layouts/application.html.erb

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

You have to include CSS manually like,

app/assets/stylesheets/

* require carts
* require layout
* require line_items
* require products
* require productshoge
* require scaffolds
* require store
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top