Rails assets not precompiling, css looks different in production -


my rails app in dev mode works , looks want to, in production looks different on chrome , safari, in safari logo images loads not font, in chrome font loads not image plus input fields little longer , mis-aligned in chrome in dev mode looks great in chrome

i been messing while , deleted public/assets few times did

rake assets:precompile rails_env=production  

with no success, precompile goes through no errors

config/application.rb:

 # settings in config/environments/* take precedence on specified here.  # application configuration should go files in config/initializers  # -- .rb files in directory 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 specified zone , make active record auto-convert zone. # run "rake -d time" list of tasks finding time zone names. default utc. # config.time_zone = 'central time (us & canada)'  # default locale :en , translations config/locales/*.rb,yml 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/production:

# code not reloaded between requests. config.cache_classes = true  # eager load code on boot. eager loads of rails , # application in memory, allowing both thread web servers # , relying on copy on write perform better. # rake tasks automatically ignore option performance. config.eager_load = true  # full error reports disabled , caching turned on. config.consider_all_requests_local       = false config.action_controller.perform_caching = true  # enable rack::cache put simple http cache in front of application # add `rack-cache` gemfile before enabling this. # large-scale production use, consider using caching reverse proxy nginx,  varnish or squid. # config.action_dispatch.rack_cache = true  # disable rails's static asset server (apache or nginx this). config.serve_static_assets = true #config.assets.compile = true  config.assets.precompile =  ['*.js', '*.css', '*.css.erb', '*.css.scss']  # compress javascripts , 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') # not fallback assets pipeline if precompiled asset missed. config.assets.compile = false config.assets.precompile << /(^[^_\/]|\/[^_])[^\/]*$/ # generate digests assets urls. config.assets.digest = true  # version of assets, change if want expire assets. config.assets.version = '1.0' 

in config/environments/production.rb file, set:

config.serve_static_assets = false (currently it's set true)

config.assets.compile = true (currently it's set false)

this should solve problem.

let me explain asking do.

  • by setting config.serve_static_assets = false, telling rails server, don't add actiondispatch::static middleware, used serve static assets.

why not?

that's because in production environment, expected run application server (like puma) behind web server (like apache/nginx), designed serve static files (including assets) directly, without bothering send request rails application server.

since, not using web server, turning off.

  • by setting config.assets.compile = true, telling rails compile requested asset @ runtime. i.e. requested asset in app/assets, vendor/assets, lib/assets , serve if found of these locations.

by default, config.assets.compile true in development, false in production environment. since, not using web server serve static assets, asking rails live compile our assets.

for further details refer asset pipeline documentation.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -