alexs333
alexs333

Reputation: 12593

Rails - customizing asset path

I have my Nginx configuration to serve assets from http://<myhost>/custom_asset_path. Unfortunately I can not change that fact of life.

Is it possible to configure Sprockets to insert custom_asset_path into the asset URL?

I.e. I want my javascript_include_tag to generate something like:

<script src="/custom_asset_path/assets/application-ccfcccSHA_continues.js" data-turbolinks-track="true"></script>

Help would be appreciated!

Upvotes: 0

Views: 1233

Answers (2)

Richard Peck
Richard Peck

Reputation: 76774

For want of an answer (I'd be interested to know this), I'd like to remind that the assets path is simply in the public folder.


Public

When you direct requests through Nginx, you're actually sending them to the public folder of your app. When you precompile your assets, they end up in public/assets, although you only see http://url.com/assets/

Thus, if you want to make a custom folder for sprockets, you'll be able to use the suggestion from @sean huber -- config.assets.prefix:

The public path that Sprockets uses by default is /assets.

This can be changed to something else: config.assets.prefix = "/some_other_path"

You must remember that any "prefix" you use should be to a member of the public directory, and thus you should expect it to be present there if you want it to work correctly.

Upvotes: 0

Sean Huber
Sean Huber

Reputation: 3985

Set a custom path for config.assets.prefix:

http://guides.rubyonrails.org/asset_pipeline.html#changing-the-assets-path

Upvotes: 1

Related Questions