Rails 3.2 and Sass do not display Application.css

I just made a major upgrade to Rails 3.2 and the latest Sass and Coffee Rails Gems, but my application file will not display as Application.css.scss. I had this in my html as such:

<%= stylesheet_link_tag 'application.css.scss' %> 

And when I look at the page source in my development mode, I get

  <link href="/assets/application.css.scss.css" media="screen" rel="stylesheet" type="text/css" /> 

What's happening??

It seems to add .css to everything I entered in stylesheet_link_tag, so if I leave it as an โ€œapplicationโ€ in my page source, I have application.css, etc.

+4
source share
3 answers

Corresponding tag format:

 <%= stylesheet_link_tag 'application' %> 

Rails automatically compiles the .scss file into a .css file - then it automatically imports the correct file. All this will take care of you.

+4
source

If you do not add the extension to stylesheet_link_tag , .css will be added automatically. I don't know why it adds the extension when you specify .scss , however.

I'm also not sure why you just aren't using <%= stylesheet_link_tag 'application' %> , which should be all that is needed.

See the documentation for stylesheet_link_tag here for more details.

+1
source

I think the default method for this in Rails 3.2 using Sprockets should have a file called application.css (not application.css.scss) that contains the Sprockets manifest code. What 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 generally better to create a new file per style scope. *= require_self *= require main_scss_file */ 

There must be at least two lines, which must be require_self, which adds content within itself and requires some_other_file, which is a link to your main scss file. Default behavior for rake assets: the default is to compile your application.js and css application

production.rb generated by Rail generators indicates that application.css is compiled by default. (Config / Medium)

  # 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' %> 
+1
source

Source: https://habr.com/ru/post/1411032/


All Articles