Rails asset pipeline - image_path helper only working in development

后端 未结 2 1563
名媛妹妹
名媛妹妹 2021-01-14 04:17

I have a problem with asset preocompilation in Rails (3.2.7).

I am including an favicon like this:



        
相关标签:
2条回答
  • 2021-01-14 04:32

    You must tell Rails which assets are to be precompiled. You do this in config/application.rb or config/environments/production.rb with the config.assets.precompile config key.

    Rails starts with a default list of assets to precompile, including ["application.js", "application.css"], but if you want your own assets to be precompiled too, you have to add them to the list.

    For example:

    # config/application.rb
    module MyApp
      class Application < Rails::Application
        # other config ...
    
        config.assets.precompile += ["screen.css", "*.png"]
      end
    end
    
    0 讨论(0)
  • 2021-01-14 04:56

    Ok, after a couple of tries I figured out, how to fix this. Nevertheless it´s a little bit strange and does not satisfy me completely. It only worked for me, when I set digest to true and provide the path to the manifest:

    config.assets.compile = false
    config.assets.digest = true
    config.assets.manifest = Rails.root.join("public/assets")
    

    It would be interesting to know, what´s behind this "logic".

    0 讨论(0)
提交回复
热议问题