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

后端 未结 3 1625
抹茶落季
抹茶落季 2020-12-15 17:40

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 ge

相关标签:
3条回答
  • 2020-12-15 18:19

    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 讨论(0)
  • 2020-12-15 18:26

    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.

    0 讨论(0)
  • 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')
    
    0 讨论(0)
提交回复
热议问题