I have set in config/environments/production.rb
config.serve_static_files = false
config.assets.compile = false
config.action_controller.asset_host = ENV['CDN_URL']
I ran RAILS_ENV=production bundle exec rake assets:precompile
and uploaded the assets folder to my assets server.
In my machine I can start a production server and it works fine. But when I upload to the production server (nginx + unicorn) the rails app keeps using a local path instead of the asset_host
<script src="/assets/application-e5b02395783a59feaf5a100d0e23806c3e2bd45296770ebac0fc756f8e1dfd53.js" data-turbolinks-track="true"></script>
How do I make it fetch the assets from asset_host
?
EDIT To explain better my problem
On remote host:
$ RAILS_ENV=production bundle exec rails console
Loading production environment (Rails 4.2.3)
irb(main):001:0> puts helper.javascript_include_tag 'application.js'
<script src="/assets/application-e5b02395783a59feaf5a100d0e23806c3e2bd45296770ebac0fc756f8e1dfd53.js"></script>
=> nil
irb(main):002:0>
On local machine:
$ RAILS_ENV=production bundle exec rails console
Loading production environment (Rails 4.2.3)
2.2.2 :001 > puts helper.javascript_include_tag 'application.js'
<script src="http://cdn.site.com/assets/application-e5b02395783a59feaf5a100d0e23806c3e2bd45296770ebac0fc756f8e1dfd53.js"></script>
=> nil
2.2.2 :002 >
Found the problem.
I'm using figaro to handle environment variables. Someone changed permissions on application.yml
and EVN['CDN_URL']
was returning nil on production servers.