问题
I just did a major upgrade to Rails 3.2 and the newest Sass and Coffee Rails Gems, but my Application file won't render as Application.css.scss. I had it in my html as such:
<%= stylesheet_link_tag 'application.css.scss' %>
And when I look at the Page Source in my Development mode I'm getting
<link href="/assets/application.css.scss.css" media="screen" rel="stylesheet" type="text/css" />
What the heck is going on!?
It seems to append .css to everything I put inside the stylesheet_link_tag, so if i leave it as just 'application' in my page source I have application.css, etc.
回答1:
The appropriate format for the tag is:
<%= stylesheet_link_tag 'application' %>
Rails automatically compiles the .scss
file into a .css
file -- then it automatically imports the correct file. It's all take care of for you.
回答2:
If you don't append an extension to stylesheet_link_tag
, .css
will be appended automatically. I do not know why it's appending the extension when you are specifying .scss
, however.
I'm also not sure why you don't just use <%= stylesheet_link_tag 'application' %>
, which should be all that's necessary.
See the documentation for stylesheet_link_tag
here for more info.
回答3:
I think the "default" way to do this in Rails 3.2 using Sprockets is to have file called application.css (not application.css.scss) that contains your Sprockets manifest code. Which should look something like this...
application.css (app/assets/stylesheets)
/*
* 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 main_scss_file
*/
There should be at least two lines one should be the require_self which adds the content inside itself and the require some_other_file which is a reference to your main scss file.The default behavior of rake assets:precompile is to compile your application.js and application css
production.rb coded generated by Rail generators specifies that application.css is compiled by default. (config/environments)
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w( search.js )
config.assets.precompile += %w( home.js )
application.erb
<%= stylesheet_link_tag 'application' %>
来源:https://stackoverflow.com/questions/10475484/rails-3-2-and-sass-not-rendering-application-css