22

I have an iframe which renders a partial and is not part of the main application layout or asset pipeline.

I'd like to include some style sheets, however I am getting this error:

 ActionView::Template::Error (960sm.css isn't precompiled):

Rails 3.1 Heroku

user229044
  • 232,980
  • 40
  • 330
  • 338
hagope
  • 5,523
  • 7
  • 38
  • 52

3 Answers3

41

Style sheets that are not included in a manifest (directly by name or indirectly via require_tree) are not precompiled, so will not accessible in production.

You need to add the sheet to the list of items to precompile in the environment application.rb.

config.assets.precompile += ['960sm.css']

And then access it in the view:

stylesheet_link_tag('960sm')
Richard Hulse
  • 10,383
  • 2
  • 33
  • 37
  • Thanks for helping me sort out the asset pipeline. – hagope Sep 29 '11 at 03:59
  • 3
    Works fine, helped me a lot, but the description on application.css gives another idea about how it works: ... /* * 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_tree . */ – Gedean Dias Oct 01 '11 at 13:43
  • this helped me...after a few hrs of finding a solution – justcode Oct 21 '12 at 04:06
  • After you changed all the config file needed to make it works... YOU MUST run touch YOURAPPDIR/tmp/restart.txt to refresh Pasenger cache – FouZ Feb 03 '13 at 01:38
4

Instead of managing a list of CSS files, you may prefer to simply adjust the extension by adding .scss to the filename.

Hence, 960sm.css would become 960sm.css.scss.

This should not break anything as valid CSS is valid SCSS.

Brad Werth
  • 17,411
  • 10
  • 63
  • 88
  • 1
    That's fine but remember *not* to add .scss in the precompile list. "Always specify an [expected compiled filename that ends with .js or .css](http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets), even if you want to add Sass or CoffeeScript files to the precompile array." – AlexChaffee Sep 10 '14 at 13:43
0

If you have a lot of standalone assets, then instead of adding each one to the list, like this

config.assets.precompile += ['960sm.css']

you may want to just precompile everything, like this:

def precompile?(path)
  %w(app lib vendor).each do |asset_root|
    assets_path = Rails.root.join(asset_root, 'assets').to_path
    return true if path.starts_with?(assets_path)
  end
  false
end

# Precompile all assets under app/assets (unless they start with _)
Rails.application.config.assets.precompile << proc do |name, path|
  starts_with_underscore = name.split('/').last.starts_with?('_')
  unless starts_with_underscore
    path = Rails.application.assets.resolve(name).to_path unless path # Rails 4 passes path; Rails 3 doesn't
    precompile?(path)
  end
end

(Based on the code in the Rails Guide.)

AlexChaffee
  • 8,092
  • 2
  • 49
  • 55