4

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.

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

2 Comments

Yea, I'm not sure why it's doing that either. I tried 'application' and like I said in my question it turns into application.css :(
That's what I mean. Why is that not working? The asset pipeline should take care of generating application.css from your scss file.
1

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' %>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.