1

I have a question about using asset_sync and a Heroku CDN. In this article, it says

Make sure you’re using the Rails AssetTagHelper methods (like image_tag). This will ensure all of your assets will reference the new asset host.

Does that mean any plain html <img> tags or refs in my app won't work? Or maybe it's just to warn against tags with an absolute URL?

EDIT: I know I can and should use image_tag and image_path in views or css. What I'm asking is, do I HAVE to?

4

2 回答 2

2

They will work but you will need to point it manually to where you are syncing your assets to, some bucket on Amazon S3. Not really recommended unless your assets will hardly ever change.

You configure your asset path in your production.rb config like so:

config.action_controller.asset_host = "http://assets.domain.com"

Then whenever you reference asset_path it will point to the asset on the host defined in your environment config.

Perhaps a solution (without understanding your exact problem) would be to do something like this:

<img src="<%= asset_path("image.png") %>" />
于 2013-04-12T05:35:40.683 回答
1

You should to use

 <%= image_path("logo.png") %>

instead of

<img src="<%= asset_path("image.png") %>" />

You can more details about this helper method here. Also As specified by andrew you need to specify asset_host in you config file. Here is a small blogpost for the same

Also:

If you want to pull css background icons/images from amazon s3 then use:

 background-image: image_url("icon.png"); // it requires scss extension ie saas and also you must has saas rails gem included.
于 2013-04-12T07:00:22.037 回答