3

In production, I use Heroku and dynamic assets on S3. It works fine. Now I try to send my statics assets to S3. I followed this tutorial https://devcenter.heroku.com/articles/cdn-asset-host-rails31

I added asset_sync gem, I configured my heroku ENVs, my config/production.rb and I run heroku run rake assets:precompile

It seems to work fine :

    Using: Directory Search of /app/public/assets
    Uploading: assets/application.js.gz
    Uploading: assets/application.css
    Uploading: assets/application-8977252f192f3e36dbd6b5142de920e3.css.gz
    Uploading: assets/eurof35-webfont-4ea19cda003d589e688cedcf9f79ddd6.eot
    Uploading: assets/application.css.gz
    Uploading: assets/application-8977252f192f3e36dbd6b5142de920e3.css
    Uploading: assets/application-a904f1bc7724b6f68e1f8d38d03a093e.js.gz
    Uploading: assets/application-a904f1bc7724b6f68e1f8d38d03a093e.js
    Uploading: assets/application.js
    AssetSync: Done.

However when I load my website, there is no CSS or JS files. When I inspect the code there is <link href="http://s3.amazonaws.com/annoncestest/assets/application-85cc4376a5de3b224db7c0548a44e7cb.css" media="all" rel="stylesheet" type="text/css" />

As you can see the CSS application which is called is not the same as I have in my S3 bucket.

Do you have any idea?

EDIT : However it works fine for application.js file, it takes the good files. But not for css files (application.css and admin.css). I tried with CloudFront and the result is the same.

CupraR_On_Rails
  • 2,449
  • 1
  • 19
  • 24

2 Answers2

2

You are using Rails 3.2 so it is much easier now. Take out the asset_sync gem. Go to Amazon and look for the CloudFront section (instead of S3). This is their CDN front end. You may have set it up to use your S3 bucket before.

With Rails 3.2 all you have to do is setup a CloudFront to use an "Origin". With an origin you give the location of your application instead of a bucket. When a user requests a file from the CDN, then the CDN will go to your app get the file and add it to the CDN cache. Since Rails Assets uses a unique filename you will always have the most up to date file.

Put the CloudFront location into your rails app as the source for assets. Then deploy and let heroku compile your assets.

Put the following in your production.rb

  # Setup amazon CDN
  config.action_controller.asset_host = "xxxxxxxxxxxxx.cloudfront.net"
Bill Leeper
  • 683
  • 1
  • 10
  • 20
  • I am trying to use CloudFont. It's the first time I use it. The problem is exactly the same. It tries to use application-78f1cb320258c94aa117a5c29a985b4d.css whereas the good file is application-8ca5a598d66f10665412206609959502.css – CupraR_On_Rails Mar 27 '12 at 13:05
0

To close the ticket I finally found the solution thanks to Heroku help. The solution is in this other ticket Why Heroku don't use the good manifest.yml

I hope it will help!

Community
  • 1
  • 1
CupraR_On_Rails
  • 2,449
  • 1
  • 19
  • 24