Rails 4: run application in production mode after assets precompile gives assets not found issue -
i using rails 4.1.8
in production.rb file have following:
config.eager_load = false config.cache_classes = false config.consider_all_requests_local = true config.action_controller.perform_caching = true config.serve_static_assets = true config.assets.js_compressor = :uglifier config.assets.compile = false config.assets.digest = false config.assets.debug = true
now after running rails_env=production rake assets:precompile
precompiles assets , store them public/assets folder file name application-ca4ad5e0582927b0a78c2b6feef3309b.js
after running application in production environment on local, throws error
actioncontroller::routingerror (no route matches [get] "/assets/application.js"):
i tried changing values of config.serve_static_assets , others.. still facing same issue.
the precompiled files saved digest values in name, ex: application-ca4ad5e0582927b0a78c2b6feef3309b.js
accessed application.js
, causing main issue.
any suggestions here?? thanks..
refer discussion here - most of assets return 404 after push heroku exact issue facing.
adding 12 factor gem: github.com/heroku/rails_12factor fixes issue. (this gem required if you're running rails 4+ on heroku). tried adding gem 'rails_12factor' in same repo working , loads assets fine.
basically rails_12factor
gem combination of 2 gems viz. rails_serve_static_assets
, rails_stdout_logging
. gem rails_serve_static_assets
sets configuration true. in config/environments/production.rb
config.serve_static_assets = true
so in general, if developing rails4
app , deploy on our own servers (say dedicated server , not heroku) setting flag config.serve_static_assets
true sufficient , don't need add rails_12 factor or other gems. here code of rails_serve_static_assets
gem used rails_12factor
gem.
module railsservestaticassets class railtie < rails::railtie config.before_initialize if rails.version >= "4.2.0" ::rails.configuration.serve_static_files = true else ::rails.configuration.serve_static_assets = true end ::rails.configuration.action_dispatch.x_sendfile_header = nil end end end
Comments
Post a Comment