2014-04-15 74 views
11

我的導軌應用程序在開發模式下工作,看起來完全按照我的要求,但在生產中它看起來不同鉻和safari,在safari徽標圖像加載但不是字體,在鉻的字體加載,但沒有圖像加輸入字段是一點點時間和鉻對齊錯誤對齊,但在開發模式,這一切都看起來不錯在鉻導軌資產沒有預編譯,css在生產中看起來不同

我一直在搞這一段時間,並刪除公衆/資產幾次做

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" 

配置/環境/製作:

# 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' 
+1

你的生產環境是什麼?你正在部署到Heroku嗎? – winston

+0

不,我在Puma上運行的Nitrous.IO上使用我自己的盒子 – franklinexpress

+1

你也運行nginx嗎?您可能需要設置配置。在生產配置中將serve_static_assets設置爲false。你也可以發佈你的徽標和CSS鏈接的代碼嗎? – winston

回答

11

在你config/environments/production.rb文件中,設置:

config.serve_static_assets = false(目前它設置爲true)

config.assets.compile = true(目前設置爲false)

這應該可以解決您的問題。

讓我解釋我要求你做的事情。

  • 通過設置config.serve_static_assets = false,我們告訴軌服務器,不添加ActionDispatch::Static中間件,它是用來提供靜態資產。

爲什麼不呢?

這是因爲在生產環境中,您需要在Web服務器(如Apache/Nginx)後面運行應用服務器(如美洲獅),該服務器旨在直接提供靜態文件(包括資產),而不會發送向rails應用服務器發送請求。

因爲您沒有使用任何網絡服務器,我們正在關閉它。

  • 通過設置config.assets.compile = true,我們告訴rails在運行時編譯請求的資產。即在app/assets,vendor/assets,lib/assets中查找所請求的資產,如果從這些位置中的任何位置找到該資源,則會查找該資產。

默認情況下,config.assets.compiletrue發展,false在生產環境中。因爲我們沒有使用Web服務器來提供靜態資產,所以我們要求rails來編譯我們的資產。

有關更多詳細信息,請參閱asset pipeline documentation

+0

'config.assets.compile = true'對我來說是一個啓發。有時候,設置的評論並不能真正闡明它的影響。這實際上更像是告訴rails期望編譯資產,而不是真的那些rails自己應該編譯它們。 – Volte