开发者

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

开发者 https://www.devze.com 2023-04-08 16:44 出处:网络
I have an iframe which renders a partial and i开发者_如何学Pythons not part of the main application layout or asset pipeline.

I have an iframe which renders a partial and i开发者_如何学Pythons 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


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


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.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号