Rails资产没有预编译,css在生产中看起来不同
在开发模式下,我的rails应用程序工作正常,外观完全符合我的要求,但在生产中,它在chrome和safari上的外观不同,在safari中,加载徽标图像,但不加载字体;在chrome中,加载字体,但不加载图像;在chrome中,输入字段稍长,对齐错误,但在开发模式下,在chrome中看起来都很棒 我已经在这方面做了一段时间,并且删除了公共/资产几次Rails资产没有预编译,css在生产中看起来不同,css,ruby-on-rails,ruby-on-rails-4,assets,Css,Ruby On Rails,Ruby On Rails 4,Assets,在开发模式下,我的rails应用程序工作正常,外观完全符合我的要求,但在生产中,它在chrome和safari上的外观不同,在safari中,加载徽标图像,但不加载字体;在chrome中,加载字体,但不加载图像;在chrome中,输入字段稍长,对齐错误,但在开发模式下,在chrome中看起来都很棒 我已经在这方面做了一段时间,并且删除了公共/资产几次 rake assets:precompile RAILS_ENV=production 如果没有成功,预编译将不会出错 config/appl
rake assets:precompile RAILS_ENV=production
如果没有成功,预编译将不会出错
config/application.rb:
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.assets.paths << "#{Rails.root}/assets/fonts"
config.assets.paths << "#{Rails.root}/assets/images"
config.assets.paths << Rails.root.join("app", "assets", "fonts")
config.assets.precompile += %w( .svg .eot .woff .ttf )
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.assets.enabled = true
#config.assets.paths << "#{Rails.root}/app/assets/fonts"
config/environments/*中的设置优先于此处指定的设置。
#应用程序配置应进入配置/初始值设定项中的文件
#--自动加载该目录中的所有.rb文件。
config.assets.path在
config/environments/production.rb
文件中,设置:
config.service\u static\u assets=false
(当前设置为true)
config.assets.compile=true
(当前设置为false)
这应该能解决你的问题
让我解释一下我要你做什么
- 通过设置
,我们告诉rails服务器,不要添加用于服务静态资产的config.service\u static\u assets=false
中间件ActionDispatch::static
- 通过设置
,我们告诉rails在运行时编译请求的资产。i、 e.在config.assets.compile=true
、app/assets
、vendor/assets
中查找请求的资产,如果从这些位置找到,则提供服务lib/assets
config.assets.compile
在开发中为true
,在生产环境中为false
。因为我们没有使用web服务器来服务静态资产,所以我们要求rails实时编译我们的资产
有关更多详细信息,请参阅。您的生产环境是什么?你要部署到Heroku吗?不,我用自己的盒子在Nitrous.IO上运行Pumare你也运行nginx吗?您可能需要在生产配置中将config.service\u static\u资产设置为false。您还可以发布徽标和CSS链接的代码吗?不运行nginx,如果我在production.rb和application.rb中有重复的设置是否重要?请在此处查看我的配置文件:。自从我部署到Heroku后,某些设置将有所不同,但请查看我的预编译设置。还要确保您在布局中使用了正确的CSS样式表链接
config.assets.compile=true
是我最喜欢的。有时,与设置相关的注释并不能真正阐明它的影响。这更像是告诉rails需要编译的资产,而不是rails本身应该编译它们。
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both thread web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Enable Rack::Cache to put a simple HTTP cache in front of your application
# Add `rack-cache` to your Gemfile before enabling this.
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
# config.action_dispatch.rack_cache = true
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
#config.assets.compile = true
config.assets.precompile = ['*.js', '*.css', '*.css.erb', '*.css.scss']
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
config.assets.paths << "#{Rails.root}/assets/fonts"
config.assets.paths << "#{Rails.root}/assets/images"
config.assets.precompile += %w( .svg .eot .woff .ttf )
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/
# Generate digests for assets URLs.
config.assets.digest = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'